nano-sql.js的基本操作
2024-08-28 13:40:17
nano-sql是一个小而快的数据库引擎, 他支持联合查询, 分组, 事务, ORM等功能, 支持 内存, indeedDB, Local Storage, WebSQL, Level DB
注意第一种写法和第二种写法的区别
<script src="https://cdn.jsdelivr.net/npm/nano-sql@1.5.3/dist/nano-sql.min.js"></script>
<script>
nSQL('users') // 设置表名.
.model([ // 设置表结构
{ key: 'id', type: 'int', props: ['pk', 'ai'] }, // pk == primary key, ai == auto incriment
{ key: 'name', type: 'string' },
{ key: 'age', type: 'int' }
])
.config({
mode: "IDB" // 本地存储使用的数据类型 IDB 表示 IndexedDB
})
.connect() // 初始化本地数据存储, 只需要执行一次
.then(function (result) {
return nSQL().query('upsert', { // 添加一行新的数据
name: "bill", age: 20
}).exec();
})
.then(function(result){
return nSQL().query('upsert', { // Add a record
name: "jim", age: 23
}).exec();
})
.then(function (result) {
return nSQL().query('select').exec(); // 从当前表中查询所有的数据
})
.then(function (result) {
console.log(result) // <= 查询结果
})
</script>
nSQL('users') // 设置表名.
.model([ // 设置表结构
{ key: 'id', type: 'int', props: ['pk', 'ai'] }, // pk == primary key, ai == auto incriment
{ key: 'name', type: 'string' },
{ key: 'age', type: 'int' }
])
.config({
mode: "IDB" // 本地存储使用的数据类型 IDB 表示 IndexedDB
})
.actions([
{
name: "add_user",
args: ["user:map"],
call: function (args, db) {
// return db.query("qusert", args.user).exec()
return db.query('upsert',args.user).exec()
}
}
]) nSQL().connect().then(function (result) {
nSQL().doAction("add_user", {
user: {
name: "jim",
age: 23
}
})
})
最新文章
- Python笔记之不可不练
- mybatis+MySQL--CRUD
- Unity手游之路<;十三>;手游代码更新策略探讨
- Codeforces Round #355 (Div. 2)-C
- Apache服务器安装配置
- 252.	Meeting Rooms
- 一种从JSON数据创建Java类的高效办法
- 1880-A. 偷吃可耻
- throw与throw的区别
- C链栈实现
- LeetCode【108. 将有序数组转换为二叉搜索树】
- Yahoo团队网站性能优化的35条黄金守则
- 阿里云服务器晚上运行定时任务报Too many connections
- golang反射举例
- P3346 [ZJOI2015]诸神眷顾的幻想乡
- windows 和linux 文件互传
- linux进程管理之信号控制
- ios读取plist文件:
- 牛客训练四:Applese 走方格(细节)
- 2018.09.23 孙悟空大战鲤鱼精(单调队列优化dp)