zoukankan      html  css  js  c++  java
  • nano-sql.js的基本操作

    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
                    }
                })
            })
  • 相关阅读:
    一些业内有名的网站收集
    WCF重载
    FCKEditor fckconfig.js配置,添加字体和大小 附:中文字体乱码问题解决
    查询第几条到第几条的数据的SQL语句
    SPOJ 9939 Eliminate the Conflict
    UVA 10534 Wavio Sequence
    HDU 3474 Necklace
    POJ 2823 Sliding Window
    UVA 437 The Tower of Babylon
    UVA 825 Walking on the Safe Side
  • 原文地址:https://www.cnblogs.com/answercard/p/9031534.html
Copyright © 2011-2022 走看看