You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSQLiteClient{constructor(db){this.db=db;}beginTransaction(){returnthis._exec('BEGIN TRANSACTION;');}commitTransaction(){returnthis._exec('COMMIT TRANSACTION;');}rollbackTransaction(){returnthis._exec('ROLLBACK TRANSACTION;');}executeQuery(sql,params){returnthis._execute('all',sql,params);}executeNonQuery(sql,params){returnthis._execute('run',sql,params).then(result=>{returnresult.changes;});}executeScalar(sql,params){returnthis._execute('get',sql,params);}executeInsert(sql,params){returnthis._execute('run',sql,params).then(result=>{returnresult.lastID;});}_execute(type,sql,params){if(!sql){thrownewError('SQL not found.');}returnnewPromise((resolve,reject)=>{// Process dynamic sql paramsql=sql.replace(/#[a-zA-Z0-9]+/g,(match,offset,source)=>{returnparams[match.slice(1)]||'';});// Not allow surplus parameters, Need get the used parameter keysletsqlNeedParamKeys=(sql.match(/@[a-zA-Z0-9]+/g)||[]).map(x=>x.slice(1));params=params||{};letsqlParams={};// Process parameterssqlNeedParamKeys.forEach(k=>{sqlParams[`@${k}`]=params[k];});this.db[type](sql,sqlParams,function(err,row){if(err){returnreject(err)}if(type==='run'){row={lastID: this.lastID,changes: this.changes};}resolve(row);});});}// Execute sql_exec(sql){returnnewPromise((resolve,reject)=>{this.db.exec(sql,(err,row)=>{if(err){returnreject(err)}resolve();});});}}module.exports=SQLiteClient;
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: