本文整理匯總了TypeScript中mysql.format函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript format函數的具體用法?TypeScript format怎麽用?TypeScript format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了format函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: update
update(tagGroup: TagGroup, option?: MariaDBBase.QueryOption): Promise<void> {
if (!option) option = {commit: true};
let sql: string = mysql.format(
"DELETE FROM tag_group_member WHERE tagGroupId = ?;",
[tagGroup.id]
);
sql += mysql.format(
"UPDATE tag_group SET name = ? WHERE tagGroupId = ?;",
[tagGroup.name, tagGroup.id]
);
const self = this;
return this.getConnection(option.transaction)
.then(connection =>
self.tags_.saveAll(tagGroup.member, {transaction: connection})
.then(() => self.executeUpdate(sql, {transaction: connection}))
.then(() =>
self.executeUpdate(
self.memberInsertSql(tagGroup),
{transaction: connection, commit: option.commit}
)
)
.then(() => tagGroup.saved())
);
}
示例2: remove
remove(tagGroup: TagGroup, option?: MariaDBBase.QueryOption): Promise<void> {
let sql: string = mysql.format(
"DELETE FROM tag_group_member WHERE tagGroupId = ?;",
[tagGroup.id]
);
sql += mysql.format(
"DELETE FROM tag_group WHERE tagGroupId = ?;",
[tagGroup.id]
);
return this.executeUpdate(sql, option);
}
示例3: insert
insert(tagGroup: TagGroup, option?: MariaDBBase.QueryOption): Promise<void> {
if (!option) option = {commit: true};
let sql: string = mysql.format(
"INSERT INTO tag_group (name) VALUES (?);",
[tagGroup.name]
);
const self = this;
return this.getConnection(option.transaction)
.then(connection => self.query(sql, {transaction: connection})
.then(result => {
tagGroup.defineId(result["insertId"]);
return self.tags_.saveAll(tagGroup.member, {transaction: connection});
})
.then(() => self.executeUpdate(
self.memberInsertSql(tagGroup),
{transaction: connection, commit: option.commit}
))
.then(() => tagGroup.saved())
);
}
示例4: format
async query<T>(sql: string, inserts: any = []) {
const SQL = format(sql, inserts);
return new Promise<T[]>((resolve, reject) => {
this._connection.query(SQL, (err, results) => {
if (err) { reject(err); } else { resolve(results); }
});
});
}
示例5: remove
remove(question: Question, option?: MariaDBBase.QueryOption): Promise<void> {
const sql: string = mysql.format(
"DELETE FROM question WHERE questionId = ?;",
[question.id]
);
return this.executeUpdate(sql, option);
}
示例6: update
update(question: Question, option?: MariaDBBase.QueryOption): Promise<void> {
const sql: string = mysql.format(
"UPDATE question SET closed = ? WHERE questionId = ?;",
[question.isClosed, question.id]
);
return this.executeUpdate(sql, option)
.then(() => question.saved());
}
示例7: insert
insert(log: RequestLog, option?: MariaDBBase.QueryOption): Promise<void> {
if (!option) option = {commit: true};
const sql1: string = mysql.format(
"INSERT INTO request_log(contextId, date, userMessage) VALUES(?, ?, ?);",
[
log.contextId,
log.date,
log.userMessage
]
);
const self = this;
let getConnection: Promise<mysql.IConnection>;
if (option.transaction) {
getConnection = Promise.resolve(option.transaction);
} else {
getConnection = this.getConnection();
}
return getConnection
.then(connection => {
option.transaction = connection;
return self.query(sql1, {transaction: option.transaction})
})
.then(result => {
const insertId: number = result["insertId"];
log.defineId(insertId);
let sql2: string = "";
for (const mmNum in log.meshinatorMessages) {
sql2 += mysql.format(
"INSERT INTO meshinator_message(logId, num, message) VALUES (?, ?, ?);",
[
insertId,
mmNum,
log.meshinatorMessages[mmNum]
]
);
}
if (sql2) {
return self.executeUpdate(sql2, option);
} else {
return Promise.resolve();
}
})
.then(() => log.saved());
}
示例8: addRecord
addRecord(record: TaggingRecord, option?: MariaDBBase.QueryOption): Promise<void> {
let sql: string = mysql.format(
"INSERT INTO tagging_record (itemId, tagId, questionId, value)"
+ "VALUES (?, ?, ?, ?);",
[
record.itemId,
record.tagId,
record.questionId,
record.value
]
);
sql += mysql.format(
"INSERT IGNORE INTO tagging (itemId, tagId, weight) VALUES (?, ?, ?);",
[
record.itemId,
record.tagId,
0
]
);
sql += mysql.format(
"UPDATE tagging SET weight = weight +(?) WHERE itemId = ? AND tagId = ?;",
[
record.value,
record.itemId,
record.tagId
]
);
return this.query(sql, option)
.then(result => {
record.defineId(result[0]["insertId"]);
record.saved();
});
}
示例9: memberInsertSql
private memberInsertSql(tagGroup: TagGroup): string {
let sql: string = "";
for (const tag of tagGroup.member) {
sql += mysql.format(
"INSERT INTO tag_group_member (tagGroupId, tagId) VALUES (?, ?);",
[tagGroup.id, tag.id]
);
}
return sql;
}
示例10: update
update(tagging: Tagging, option?: MariaDBBase.QueryOption): Promise<void> {
// weightだけ更新する
let sql: string
= "UPDATE tagging SET weight = ?" // tagging.weight
+ " WHERE taggingId = ?;"; // tagging.id
// プレースホルダに代入
sql = mysql.format(sql, [
tagging.weight,
tagging.id
]);
// クエリ実行
return this.executeUpdate(sql, option)
.then(() => tagging.saved());
}
示例11: remove
remove(tagging: Tagging, option?: MariaDBBase.QueryOption): Promise<void> {
let sql: string
// taggingテーブルからの削除
= "DELETE FROM tagging WHERE taggingId = ?; "// tagging.id
// tagging_recordテーブルからの削除
+ "DELETE FROM tagging_record"
+ " WHERE itemId = ?" // tagging.tagId
+ " AND tagId = ?;"; // tagging.itemId
sql = mysql.format(sql, [
tagging.id,
tagging.tagId,
tagging.itemId
]);
return this.executeUpdate(sql, option);
}
示例12: insert
insert(tagging: Tagging, option?: MariaDBBase.QueryOption): Promise<void> {
// INSERT文作成
let sql: string
= "INSERT INTO tagging(itemId, tagId, weight) VALUES(?, ?, ?);";
// プレースホルダに値を入れる
sql = mysql.format(sql, [
tagging.itemId,
tagging.tagId,
tagging.weight
]);
// クエリ実行
return this.query(sql, option)
.then(result => {
tagging.defineId(result["insertId"]);
tagging.saved();
});
}
示例13: VALUES
.then(result => {
const insertId: number = result["insertId"];
log.defineId(insertId);
let sql2: string = "";
for (const mmNum in log.meshinatorMessages) {
sql2 += mysql.format(
"INSERT INTO meshinator_message(logId, num, message) VALUES (?, ?, ?);",
[
insertId,
mmNum,
log.meshinatorMessages[mmNum]
]
);
}
if (sql2) {
return self.executeUpdate(sql2, option);
} else {
return Promise.resolve();
}
})
示例14: insert
insert(question: Question, option?: MariaDBBase.QueryOption): Promise<void> {
let qType: string;
if (question instanceof NiceToMeetYouQuestion) {
qType = "NiceToMeetYou";
} else if (question instanceof ModeSelectQuestion) {
qType = "ModeSelect";
} else if (question instanceof SimpleTagQuestion) {
qType = "SimpleTag";
} else if (question instanceof SimpleItemRecommendQuestion) {
qType = "SimpleItemRecommend";
} else if (question instanceof ContinueRecommendQuestion) {
qType = "ContinueRecommend";
} else if (question instanceof TagGroupQuestion) {
qType = "TagGroup";
} else if (question instanceof UnimplementedQuestion) {
qType = "Unimplemented";
}
const sql: string = mysql.format(
"INSERT INTO question (type, about, contextId, closed) VALUES (?, ?, ?, ?);",
[qType, question.about, question.contextId, question.isClosed]
);
return this.query(sql, option)
.then(result => {
question.defineId(result["itemId"]);
question.saved();
});
}
示例15: query
query(queryStr: string, params?: any[]): Promise<any> {
return this.manager.query(params ? mysql.format(queryStr, params) : queryStr)
}