• sqlite note 码农


    1: 增加db,名称 my.db
    https://www.sqlite.org/download.html
    您需要下载 sqlite-tools-win32-*.zip 和 sqlite-dll-win32-*.zip 压缩文件

    CREATE TABLE TaoCan( ID INT PRIMARY KEY NOT NULL, Phone varchar(20), Result varchar(200) , );


    2:npm install sqlite3


    3:flow


    3.1 save to db every 1000

    INSERT INTO TaoCan(Phone,Result) VALUES ()

    3.2 download to excel
    3.3 delete data

    4:nodejs 封装sqlite

    const sqlite3 = require('sqlite3').verbose()
    var db
      
    exports.db = db
      
    exports.open=function(path) {
     return new Promise(function(resolve) {
     this.db = new sqlite3.Database(path,
      function(err) {
       if(err) reject("Open error: "+ err.message)
       else resolve(path + " opened")
      }
     )
     })
    }
      
    // any query: insert/delete/update
    exports.run=function(query) {
     return new Promise(function(resolve, reject) {
      this.db.run(query,
       function(err) {
        if(err) reject(err.message)
        else resolve(true)
      })
     })
    }
      
    // first row read
    exports.get=function(query, params) {
     return new Promise(function(resolve, reject) {
      this.db.get(query, params, function(err, row) {
       if(err) reject("Read error: " + err.message)
       else {
        resolve(row)
       }
      })
     })
    }
      
    // set of rows read
    exports.all=function(query, params) {
     return new Promise(function(resolve, reject) {
      if(params == undefined) params=[]
      
      this.db.all(query, params, function(err, rows) {
       if(err) reject("Read error: " + err.message)
       else {
        resolve(rows)
       }
      })
     })
    }
      
    // each row returned one by one
    exports.each=function(query, params, action) {
     return new Promise(function(resolve, reject) {
      var db = this.db
      db.serialize(function() {
       db.each(query, params, function(err, row) {
        if(err) reject("Read error: " + err.message)
        else {
         if(row) {
          action(row)
         }
        }
       })
       db.get("", function(err, row) {
        resolve(true)
       })  
      })
     })
    }
      
    exports.close=function() {
     return new Promise(function(resolve, reject) {
      this.db.close()
      resolve(true)
     })
    }

    From <https://www.jb51.net/article/156253.htm>
    https://www.jianshu.com/p/33b132078b05
    https://www.codeleading.com/article/17874614799/
    https://www.runoob.com/sqlite/sqlite-insert.html

  • 相关阅读:
    c#调用c++动态链接库的问题
    “LC.exe”已退出,代码为 -1
    MVC部署到iis
    计算机上没有找到was服务
    无法查找或打开pdb文件
    用WCF服务来动态的获取本地XML省市区文档
    关于使用条码打印机指令打印汉字的问题
    关于SQL SERVER导出数据的问题!
    应用CLR的线程池
    所有的异常都要使用try catch 语句捕获?
  • 原文地址:https://www.cnblogs.com/dming4/p/16318640.html
Copyright © 2020-2023  润新知