项目作者: BaseMax

项目描述 :
edb-sqlite: Easy Database SQLite NodeJs
高级语言: JavaScript
项目地址: git://github.com/BaseMax/edb-sqlite-nodejs.git
创建时间: 2020-12-01T14:41:05Z
项目社区:https://github.com/BaseMax/edb-sqlite-nodejs

开源协议:MIT License

下载


edb-sqlite-nodejs

Easy Database Sqlite Node-Js

For some small applications that use SQLite Database, I needed to design a small library to simplify my work.
And connect to the database without any worries.
So I also published the library that I implemented for the projects here.

Import edb-sqlite

  1. const database = require(`./database`)

Using edb-sqlite

Open/Connect DB

  1. database.open(`database.db`)

Create Table

  1. database.run(`CREATE TABLE IF NOT EXISTS 'record'
  2. (
  3. ID INTEGER PRIMARY KEY NOT NULL,
  4. meetingId CHAR(70) NOT NULL,
  5. recordId CHAR(70) NOT NULL,
  6. status INTEGER NOT NULL
  7. )`)

update

  1. database.update(`UPDATE langs SET name = ? WHERE name = ?`, [`test`, `c`])

Delete

  1. database.delete(`DELETE FROM langs WHERE rowid=?`, [1])

Insert

  1. database.insert(`INSERT INTO langs(name) VALUES(?)`, [4])

Select(s) Rows

  1. database.selects(`SELECT * FROM record WHERE status = 0 ORDER BY ID ASC LIMIT 5`, [],
  2. (rows) => {
  3. console.log(rows)
  4. for(let row of rows) {
  5. console.log(row)
  6. }
  7. })

Single Select

  1. database.select(`SELECT * FROM record WHERE meetingId = ? AND recordId = ?`, [5, 8], (res) => {
  2. console.log(res)
  3. })

Single Select Count

  1. database.select(`SELECT COUNT(*) as count FROM record WHERE meetingId = ? AND recordId = ?`, [5, 8], (res) => {
  2. if(res[`count`]) {
  3. console.log(res[`count`])
  4. } else {
  5. console.log(`Error: ${res}`)
  6. }
  7. })

Close/Disconnect db

  1. database.close()

TODO EDB-Sqlite

  • Adding example js files
  • Publish package to npm package manager

I appreciate if anyone does these and send PR to me.


Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers.

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team