当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript SQLiteObject.transaction方法代码示例

本文整理汇总了TypeScript中@ionic-native/sqlite.SQLiteObject.transaction方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SQLiteObject.transaction方法的具体用法?TypeScript SQLiteObject.transaction怎么用?TypeScript SQLiteObject.transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@ionic-native/sqlite.SQLiteObject的用法示例。


在下文中一共展示了SQLiteObject.transaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: populateTable

  /**
   * Populates a given table with data
   * @param  {table} table The table definition, should be {name: string, primary: string, members: {"column_name": "int|real|boolean|string"}}
   * @param  {Enumerable} data  Object or Array with data to insert, should be contain objects with the same keys as the table columns
   * @return {SQL_results}  Returns SQL results
   */
  @DBMethod
  async populateTable(table: TableDef, data, shouldDelete = true) {
    return this.db.transaction(tx => {
      if (shouldDelete) {
        tx.executeSql('DELETE FROM ' + table.name + ';');
      }

      (Array.isArray(data) ? data : Object.values(data)).forEach(singleData => {
        var insertData = [];
        for (var member in table.members) {
          /*
          * We need to remove some line separators because of a bug in cordova
          * See https://github.com/litehelpers/Cordova-sqlite-storage/issues/147
          */
          if (singleData[member] != undefined) {
            const escapedData = ('' + singleData[member]).replace(/[\u2028\u2029]/g, '\n');
            insertData.push(escapedData);
          } else {
            insertData.push(null);
          }
        }
        var query = `INSERT OR IGNORE INTO ${table.name} VALUES(${Array(insertData.length)
          .fill('?')
          .join(',')})`;
        tx.executeSql(query, insertData);
      });
    });
  }
开发者ID:ifiske,项目名称:iFiske,代码行数:34,代码来源:database.ts

示例2: function

 db.executeSql(query, []).then((result) => {
   for(let i = 0; i < result.rows.length; i++)
     tables.push(result.rows.item(i).tbl_name);
   db.transaction(function(tx){
     for(let tblName of tables){
       if(tblName.toLowerCase() === "MergeIdentity".toLowerCase()){
         tx.executeSql("UPDATE MergeIdentity SET MergeUpdate=0 WHERE MergeUpdate > 0;", [], null, null);
       }
       if(tblName.toLowerCase() !== "MergeDelete".toLowerCase() && tblName.toLowerCase() !== "MergeIdentity".toLowerCase()){
         query = "SELECT sql FROM sqlite_master WHERE type='trigger' AND name LIKE 'trMergeUpdate_" + tblName + "'";
         let updTriggerSQL = null;
         tx.executeSql(query, [],
           function(transaction, result) {
             updTriggerSQL = result.rows.item(0)[0];
             if (updTriggerSQL != null){
               tx.executeSql("DROP trigger trMergeUpdate_" + tblName, [], null, null);
               tx.executeSql("UPDATE " + tblName + " SET MergeUpdate=0 WHERE MergeUpdate > 0;", [], null, null);
               tx.executeSql(updTriggerSQL, [], null, null);
             }
           }, function(transaction, error){
         });
       }
     }
     tx.executeSql("DELETE FROM MergeDelete;",[],null,null);
   }).then(() => {
     resolve();
   }).catch((err) => {
     reject("Error while clearing local markers");
   });
 }).catch((err) => {
开发者ID:sqlite-sync,项目名称:SQLite-sync.com,代码行数:30,代码来源:sqlite-sync.ts

示例3: Promise

 return new Promise((resolve, reject) => {
   db.transaction(tx => {
     tx.executeSql(
       statement,
       params,
       (itx, res) => {
         resolve(res);
       },
       (itx, err) => {
         reject(err);
       },
     );
   });
 });
开发者ID:ifiske,项目名称:iFiske,代码行数:14,代码来源:database.ts

示例4: switch

            this.openDatabase().then((db: SQLiteObject) => {
              db.transaction(function(tx){
                if(SqliteSyncObject.TriggerInsertDrop.length > 0){
                  tx.executeSql(SqliteSyncObject.TriggerInsertDrop, [], null, null);
                }
                if(SqliteSyncObject.TriggerUpdateDrop.length > 0){
                  tx.executeSql(SqliteSyncObject.TriggerUpdateDrop, [], null, null);
                }
                if(SqliteSyncObject.TriggerDeleteDrop.length > 0){
                  tx.executeSql(SqliteSyncObject.TriggerDeleteDrop, [], null, null);
                }
                for(let record of SqliteSyncObject.Records){
                  switch(record.Action){
                    case '1':
                      tx.executeSql(SqliteSyncObject.QueryInsert, record.Columns, null, null);
                      break;
                    case '2':
                      tx.executeSql(SqliteSyncObject.QueryUpdate, record.Columns, null, null);
                      break;
                    case '3':
                      tx.executeSql(SqliteSyncObject.QueryDelete + "?", record.Columns, null, null);
                      break;
                  }
                }

                if(SqliteSyncObject.TriggerInsert.length > 0){
                    tx.executeSql(SqliteSyncObject.TriggerInsert, [], null, null);
                }
                if(SqliteSyncObject.TriggerUpdate.length > 0){
                    tx.executeSql(SqliteSyncObject.TriggerUpdate, [], null, null);
                }
                if(SqliteSyncObject.TriggerDelete.length > 0){
                    tx.executeSql(SqliteSyncObject.TriggerDelete, [], null, null);
                }

              }).then(() => {
                this.CommmitSynchronization(syncUrl, SqliteSyncObject.SyncId).then(() => {
                  resolve();
                }).catch((err) => {
                  reject(err);
                });
              }).catch((err) => {
                reject("Error while syncing databases!");
              });
            }).catch((err) => {
开发者ID:sqlite-sync,项目名称:SQLite-sync.com,代码行数:45,代码来源:sqlite-sync.ts

示例5: cleanTable

 @DBMethod
 async cleanTable(table: string) {
   return this.db.transaction(tx => {
     tx.executeSql('DELETE FROM ' + table + ';');
   });
 }
开发者ID:ifiske,项目名称:iFiske,代码行数:6,代码来源:database.ts


注:本文中的@ionic-native/sqlite.SQLiteObject.transaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。