當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mysql.format函數代碼示例

本文整理匯總了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())
            );

    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:30,代碼來源:TagGroupMariaDBContainer.ts

示例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);

    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:15,代碼來源:TagGroupMariaDBContainer.ts

示例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())
            );

    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:25,代碼來源:TagGroupMariaDBContainer.ts

示例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); }
     });
   });
 }
開發者ID:chasidic,項目名稱:mysql,代碼行數:8,代碼來源:MysqlConnection.ts

示例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);

    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:10,代碼來源:QuestionMariaDBContainer.ts

示例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());

    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:11,代碼來源:QuestionMariaDBContainer.ts

示例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());
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:51,代碼來源:RequestLogMariaDBContainer.ts

示例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();
            });
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:37,代碼來源:TaggingMariaDBAccessor.ts

示例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;
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:15,代碼來源:TagGroupMariaDBContainer.ts

示例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());
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:17,代碼來源:TaggingMariaDBAccessor.ts

示例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);
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:19,代碼來源:TaggingMariaDBAccessor.ts

示例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();
            });
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:20,代碼來源:TaggingMariaDBAccessor.ts

示例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();
                }
            })
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:22,代碼來源:RequestLogMariaDBContainer.ts

示例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();
            });
    }
開發者ID:Huruikagi,項目名稱:Meshinator,代碼行數:38,代碼來源:QuestionMariaDBContainer.ts

示例15: query

 query(queryStr: string, params?: any[]): Promise<any> {
     return this.manager.query(params ? mysql.format(queryStr, params) : queryStr)
 }
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:3,代碼來源:db.ts


注:本文中的mysql.format函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。