本文整理汇总了TypeScript中knex.insert函数的典型用法代码示例。如果您正苦于以下问题:TypeScript insert函数的具体用法?TypeScript insert怎么用?TypeScript insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了insert函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: CHECK
return knex.schema.hasColumn("markets", "validityBondSize").then(async(exists) => {
if (!exists) {
await knex.schema.table("markets", (t) => {
t.string("validityBondSize").defaultTo("0");
t.string("transactionHash", 66);
t.specificType("logIndex", "integer NOT NULL CONSTRAINT \"nonnegativelogIndex\" CHECK (\"logIndex\" >= 0)").defaultTo(0);
});
}
const etherTokenRow = await knex("tokens").where("contractAddress", "ether");
if (etherTokenRow.length === 0) {
await knex.insert({contractAddress: ETHER, symbol: ETHER}).into("tokens");
await knex.insert({token: ETHER, supply: null}).into("token_supply");
}
});
开发者ID:AugurProject,项目名称:augur_node,代码行数:14,代码来源:20181009172200_market_validity_bond_size.ts
示例2: insertPayout
export async function insertPayout(db: Knex, marketId: Address, payoutNumerators: Array<string|number|null>, invalid: boolean, tentativeWinning: boolean): Promise<number> {
const payoutRow: { [index: string]: string|number|boolean|null } = {
marketId,
isInvalid: invalid,
};
payoutNumerators.forEach((value, i): void => {
if (value == null) return;
payoutRow["payout" + i] = new BigNumber(value, 10).toString();
});
const payoutIdRow: { payoutId: number }|null = await db.select("payoutId").from("payouts").where(payoutRow).first();
if (payoutIdRow != null) {
return payoutIdRow.payoutId;
} else {
const payoutRowWithTentativeWinning = Object.assign({},
payoutRow,
{ tentativeWinning: Number(tentativeWinning) },
);
let query = db.insert(payoutRowWithTentativeWinning).into("payouts");
if (db.client.config.client !== "sqlite3") {
query = query.returning("payoutId");
}
const payoutIdRow: Array<number> = await query;
if (!payoutIdRow || !payoutIdRow.length) throw new Error("No payoutId returned");
return payoutIdRow[0];
}
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:26,代码来源:database.ts
示例3: updateOutcomeValuesFromFinalization
export async function updateOutcomeValuesFromFinalization(db: Knex, augur: Augur, marketId: Address, transactionHash: string, blockNumber: number, logIndex: number): Promise<void> {
const payouts: PayoutAndMarket<BigNumber> = await db
.first(["payouts.payout0", "payouts.payout1", "payouts.payout2", "payouts.payout3", "payouts.payout4", "payouts.payout5", "payouts.payout6", "payouts.payout7", "markets.minPrice", "markets.maxPrice", "markets.numTicks"])
.from("payouts")
.where("payouts.marketId", marketId)
.join("markets", function() {
this.on("payouts.marketId", "markets.marketId");
});
const timestamp = getCurrentTime();
const maxPrice = payouts.maxPrice;
const minPrice = payouts.minPrice;
const numTicks = payouts.numTicks;
const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
const insertValues = [];
for (let i: number = 0; i <= 7; i++) {
const column = `payout${i}`;
const payoutValue = payouts[column as keyof PayoutAndMarket<BigNumber>];
if (payoutValue != null) {
const value = payoutValue.times(tickSize).plus(minPrice);
insertValues.push({
marketId,
transactionHash,
blockNumber,
logIndex,
outcome: i,
value: value.toString(),
timestamp,
});
}
}
await db.insert(insertValues).into("outcome_value_timeseries");
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:32,代码来源:update-outcome-value.ts
示例4: insertTransactionHash
export async function insertTransactionHash(db: Knex, blockNumber: number, transactionHash: string) {
if (transactionHash === null) throw new Error("Received null transactionHash from getLogs request. Your Ethereum node might be in light mode with bug: https://github.com/paritytech/parity-ethereum/issues/9929");
const txHashRows: Array<TransactionHashesRow> = await db("transactionHashes").where({ transactionHash });
if (!txHashRows || !txHashRows.length) {
await db.insert({ blockNumber, transactionHash }).into("transactionHashes");
}
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:7,代码来源:process-block.ts
示例5: async
return async (db: Knex) => {
const marketId = log.market;
const marketsRow: MarketsRow<BigNumber>|undefined = await db.first("minPrice", "maxPrice", "numTicks", "numOutcomes").from("markets").where({ marketId });
if (!marketsRow) throw new Error(`market not found: ${marketId}`);
const minPrice = marketsRow.minPrice;
const maxPrice = marketsRow.maxPrice;
const numTicks = marketsRow.numTicks;
const numOutcomes = marketsRow.numOutcomes;
const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
const numCompleteSets = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(log.numCompleteSets, 10), tickSize);
const completeSetPurchasedData: CompleteSetsRow<string> = {
marketId,
account: log.account,
blockNumber: log.blockNumber,
universe: log.universe,
eventName: log.eventName,
transactionHash: log.transactionHash,
logIndex: log.logIndex,
numCompleteSets: numCompleteSets.toString(),
numPurchasedOrSold: numCompleteSets.toString(),
};
const eventName = log.eventName as keyof typeof SubscriptionEventNames;
await db.insert(completeSetPurchasedData).into("completeSets");
augurEmitter.emit(SubscriptionEventNames[eventName], completeSetPurchasedData);
await updateMarketOpenInterest(db, marketId);
};
开发者ID:AugurProject,项目名称:augur_node,代码行数:26,代码来源:completesets.ts
示例6: async
return async(db: Knex) => {
const amount: BigNumber = new BigNumber(log.amount, 10);
const price: BigNumber = new BigNumber(log.price, 10);
const orderType: string = log.orderType;
const moneyEscrowed: BigNumber = new BigNumber(log.moneyEscrowed, 10);
const sharesEscrowed: BigNumber = new BigNumber(log.sharesEscrowed, 10);
const shareToken: Address = log.shareToken;
const tokensRow: TokensRow|undefined = await db.first("marketId", "outcome").from("tokens").where({ contractAddress: shareToken });
if (!tokensRow) throw new Error(`market and outcome not found for shareToken ${shareToken} (${log.transactionHash}`);
const marketId = tokensRow.marketId;
const outcome = tokensRow.outcome!;
const marketsRow: MarketsRow<BigNumber> = await db.first("minPrice", "maxPrice", "numTicks", "numOutcomes").from("markets").where({ marketId });
if (!marketsRow) throw new Error(`market not found: ${marketId}`);
const minPrice = marketsRow.minPrice;
const maxPrice = marketsRow.maxPrice;
const numTicks = marketsRow.numTicks;
const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
const numOutcomes = marketsRow.numOutcomes;
const fullPrecisionAmount = augur.utils.convertOnChainAmountToDisplayAmount(amount, tickSize);
const fullPrecisionPrice = augur.utils.convertOnChainPriceToDisplayPrice(price, minPrice, tickSize);
const orderTypeLabel = orderType === "0" ? "buy" : "sell";
const displaySharesEscrowed = augur.utils.convertOnChainAmountToDisplayAmount(sharesEscrowed, tickSize).toString();
const displayTokensEscrowed = fixedPointToDecimal(moneyEscrowed, BN_WEI_PER_ETHER).toString();
const orderData: OrdersRow<string> = {
marketId,
blockNumber: log.blockNumber,
transactionHash: log.transactionHash,
logIndex: log.logIndex,
outcome,
shareToken,
orderCreator: log.creator,
orderState: OrderState.OPEN,
tradeGroupId: log.tradeGroupId,
orderType: orderTypeLabel,
price: formatOrderPrice(orderTypeLabel, minPrice, maxPrice, fullPrecisionPrice),
amount: formatOrderAmount(fullPrecisionAmount),
originalAmount: formatOrderAmount(fullPrecisionAmount),
fullPrecisionPrice: fullPrecisionPrice.toString(),
fullPrecisionAmount: fullPrecisionAmount.toString(),
originalFullPrecisionAmount: fullPrecisionAmount.toString(),
originalTokensEscrowed: displayTokensEscrowed,
originalSharesEscrowed: displaySharesEscrowed,
tokensEscrowed: displayTokensEscrowed,
sharesEscrowed: displaySharesEscrowed,
};
const orderId = { orderId: log.orderId };
const ordersRows: Array<Partial<OrdersRow<BigNumber>>> = await db.select("marketId").from("orders").where(orderId);
let upsertOrder: QueryBuilder;
if (!ordersRows || !ordersRows.length) {
upsertOrder = db.insert(Object.assign(orderData, orderId)).into("orders");
} else {
upsertOrder = db.from("orders").where(orderId).update(orderData);
}
await upsertOrder;
await marketPendingOrphanCheck(db, orderData);
augurEmitter.emit(SubscriptionEventNames.OrderCreated, Object.assign({}, log, orderData));
};
开发者ID:AugurProject,项目名称:augur_node,代码行数:58,代码来源:order-created.ts
示例7: increaseTokenSupply
export async function increaseTokenSupply(db: Knex, augur: Augur, token: Address, amount: BigNumber) {
const oldSupply: SupplyResult = await db.first("supply").from("token_supply").where({ token });
if (oldSupply == null) {
await db.insert({ token, supply: amount.toString() }).into("token_supply");
} else {
const supply = oldSupply.supply.plus(amount);
await db.update({ supply: supply.toString() }).into("token_supply").where({ token });
}
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:9,代码来源:increase-token-supply.ts
示例8: updateMarketState
export async function updateMarketState(db: Knex, marketId: Address, blockNumber: number, reportingState: ReportingState) {
const marketStateDataToInsert = { marketId, reportingState, blockNumber };
let query = db.insert(marketStateDataToInsert).into("market_state");
if (db.client.config.client !== "sqlite3") {
query = query.returning("marketStateId");
}
const marketStateId: Array<number> = await query;
if (!marketStateId || !marketStateId.length) throw new Error("Failed to generate new marketStateId for marketId:" + marketId);
return setMarketStateToLatest(db, marketId);
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:10,代码来源:database.ts
示例9: marketPendingOrphanCheck
async function marketPendingOrphanCheck(db: Knex, orderData: OrdersRow<string>) {
const pendingOrderData = {
marketId: orderData.marketId,
outcome: orderData.outcome,
orderType: orderData.orderType,
};
const result: { count: number } = await db.first(db.raw("count(*) as count")).from("pending_orphan_checks").where(pendingOrderData);
if (result.count > 0) return;
return await db.insert(pendingOrderData).into("pending_orphan_checks");
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:10,代码来源:order-created.ts
示例10: increaseTokenBalance
export async function increaseTokenBalance(db: Knex, augur: Augur, token: Address, owner: Address, amount: BigNumber, log: FormattedEventLog) {
if (isLegacyReputationToken(augur, token)) return;
const oldBalance: BalanceResult = await db.first("balance").from("balances").where({ token, owner });
let balance = amount;
if (oldBalance == null) {
await db.insert({ owner, token, balance: balance.toString() }).into("balances");
} else {
balance = oldBalance.balance.plus(amount);
await db.update({ balance: balance.toString() }).into("balances").where({ token, owner });
}
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:11,代码来源:increase-token-balance.ts
注:本文中的knex.insert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论