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
}
})
})

最新文章

  1. Python笔记之不可不练
  2. mybatis+MySQL--CRUD
  3. Unity手游之路&lt;十三&gt;手游代码更新策略探讨
  4. Codeforces Round #355 (Div. 2)-C
  5. Apache服务器安装配置
  6. 252. Meeting Rooms
  7. 一种从JSON数据创建Java类的高效办法
  8. 1880-A. 偷吃可耻
  9. throw与throw的区别
  10. C链栈实现
  11. LeetCode【108. 将有序数组转换为二叉搜索树】
  12. Yahoo团队网站性能优化的35条黄金守则
  13. 阿里云服务器晚上运行定时任务报Too many connections
  14. golang反射举例
  15. P3346 [ZJOI2015]诸神眷顾的幻想乡
  16. windows 和linux 文件互传
  17. linux进程管理之信号控制
  18. ios读取plist文件:
  19. 牛客训练四:Applese 走方格(细节)
  20. 2018.09.23 孙悟空大战鲤鱼精(单调队列优化dp)

热门文章

  1. CPP_const&amp;static
  2. python -修改文件中某一行
  3. QButton
  4. WinForm 控件键盘消息处理剖析(转)
  5. Android指南 - 样式和主题
  6. android开发(40) 初试 Volley - GoogleI02013上的“快速,简单的网络通讯库”
  7. Vue路由学习笔记
  8. 目录_Java内存分配(直接内存、堆内存、Unsafel类、内存映射文件)
  9. htop VS top
  10. android 在HTML中显示bitmap