1.2.11 • Published 5 years ago

sqlite-simple v1.2.11

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

sqlite-simple

database

  • pushTable([...options])
  • ready()
  • transaction(callback[, serialize])

table

  • insert(data[, isResult])
  • delete(data)
  • update(data[, isResult])
  • select(fields='*')
  • put(data, fields[, dataHandler])
  • bulkInsert(array[, isResult])
  • bulkDelete(array)
  • bulkUpdate(array[, isResult])
  • bulkPut(array[, fields][, dataHandler])
  • get(where[, fields])
  • each(where[, fields])

###创建数据库、表 注意: 如果需要在 insert、put 操作后获取返回值添加 uniqueKey

const DataBase = require('sqlite-simple');

const db=new DataBase("./a.db",function(db){
	db.pushTable({
		tableName: 'classify',
		fields: {
			"id": ["integer", "autoincrement"],
			"name": ["text", "NOT NULL"]
		},
		primaryKey: ["id"]
	},{
		tableName:'list',
		fields: {
			"id": ["integer", "autoincrement"],
			"title": ["text", "NOT NULL"],
			"content":["text", "NOT NULL"]//, "UNIQUE" ,"DEFAULT(...)"
		},
		primaryKey: ["id"],
		//如果需要在 insert、put 操作后获取返回值添加这个配置
		uniqueKey: ["title"]
		/* CREATE TABLE IF NOT EXISTS ${tableName}(
		 * for(field in fields)
		 * [${field}] ${fields[field].join(" ")}
		 * 
		 * PRIMARY KEY(${primaryKey})
		 * )
		 */
	})
});

###bulkInsert 注意: 数据库是异步创建,如果要立即操作数据, 加 ready

db.ready().then(function(db){
	db.list.bulkInsert([
		{
			title:"标题1",
			content:"内容1"
		},
		{
			title:"标题2",
			content:"内容2"
		}
	]).then(function(e){
		console.log(e)
	}).catch(function(e){
		console.error(e)
	})
})

###select 注意: 对应 sqlite3 中的 db.all

//所有字段
db.list.select().then(function(result){
	console.log(result)
}).catch(function(e){
	console.error(e)
})
//部分字段
db.list.select(["code","name"]).then(function(result){
	console.log(result)
}).catch(function(e){
	console.error(e)
})
//部分字段
db.list.select("code,name").then(function(result){
	console.log(result)
}).catch(function(e){
	console.error(e)
})
1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago