{"id":17301730,"url":"https://github.com/thinkeridea/jsondb","last_synced_at":"2025-04-14T12:42:22.994Z","repository":{"id":32233494,"uuid":"35807605","full_name":"thinkeridea/jsonDB","owner":"thinkeridea","description":"jsonDB是js的一个类库，实现使用SQL语句对json数据增删改查。","archived":false,"fork":false,"pushed_at":"2015-05-19T09:29:33.000Z","size":357,"stargazers_count":41,"open_issues_count":1,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T01:53:27.754Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkeridea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-18T08:59:18.000Z","updated_at":"2025-03-02T07:35:28.000Z","dependencies_parsed_at":"2022-08-24T10:00:07.624Z","dependency_job_id":null,"html_url":"https://github.com/thinkeridea/jsonDB","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkeridea%2FjsonDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkeridea%2FjsonDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkeridea%2FjsonDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkeridea%2FjsonDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkeridea","download_url":"https://codeload.github.com/thinkeridea/jsonDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883163,"owners_count":21177169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T11:45:20.119Z","updated_at":"2025-04-14T12:42:22.963Z","avatar_url":"https://github.com/thinkeridea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"###jsonDB\n\njsonDB是js的一个类库，实现使用SQL语句对json数据增删改查。\u003cbr/\u003e\njsonDB的构建源自于HTML5本地存储的一个应用需求，可以通过sql对json数据进行增删改查，同时该类库提供强大的where检索条件，数据排序，limit查询条件限制等数据库基本功能。\u003cbr/\u003e\n通过jsonDB可以轻松维护一个库/表或多个库/表，而无需额外实现json的数据的维护等，在该类库完善以后为简化sql操作，基于jsonDB核心模块扩展了连贯操作模型，简化对jsonDB的操作以及sql语句出错的概率。\n\t\n当前版本的不足： \n-------------------\n\t1.无法支持查询字段运算 \n\t2.不支持对没有选取的查询字段排序 \n\t3.只支持单个字段排序，无法进行组合排序操作 \n\t4.update、delete语句不支持order by子句，导致limit子句功能弱化 \n\t5.编写where条件是必须使用()包含where条件 \n\t6.无法选取深层次的字段作为返回字段 \n\t7.没有错误或异常解决方案 \n\t8.不支持外部扩展 \n \njsonDB基础应用示例：\n-------------------\n```javascript\n//创建一张user数据表，并定义一个DB的jsonDB别名  \nvar data = [{username:'张三',sex:'男',birthday:{year:2000,month:6,day:18}},{username:'李红',sex:'女',birthday:{year:1986,month:9,day:22}}];  \n//以下方法可以通过两种方式获取别名，一个是通过init方法获取(推荐)，一个是获取jsonDB()方法的返回值  \n//以后示例中都将使用init()方法创建的别名操作数据  \nvar jDB = jsonDB(data,'user').init('DB');  \n  \n//插入一条新的数据  \ndata = {username:'李想',sex:'男',birthday:{year:1990,month:2,day:15}};  \nDB.insert(data,'user');  \n  \n//查询姓名为李红的性别,where条件必须加()否者会出现错误  \nvar result =DB.query('select sex from user where (username=\"李红\")');  \n//结果：[{\"sex\":\"女\"}]  \n  \n//查询2000年之前出生的且按出生年先后排序  \nvar result =DB.query('select * from user where (birthday.year\u003c2000) order by birthday.year asc');  \n//结果：[{\"username\":\"李红\",\"sex\":\"女\",\"birthday\":{\"year\":1986,\"month\":9,\"day\":22}},{\"username\":\"李想\",\"sex\":\"男\",\"birthday\":{\"year\":1990,\"month\":2,\"day\":15}}] \n\n//查询年龄最小的两个人  \nvar result =DB.query('select * from user order by birthday.year desc limit 2');  \n//查询结果：[{\"username\":\"张三\",\"sex\":\"男\",\"birthday\":{\"year\":2000,\"month\":6,\"day\":18}},{\"username\":\"李想\",\"sex\":\"男\",\"birthday\":{\"year\":1990,\"month\":2,\"day\":15}}]  \n  \n//修改李红的出生日期  \nvar result =DB.query('update user set birthday.year=1991 where (username=\"李红\") limit 1');  \n//影响条数为一条，可以通过DB.findAll('user')获取全部数据查看是否被修改成功  \n  \n//删除姓名为李想的数据  \nvar result =DB.query('delete from user where (username=\"李想\") limit 1');  \n//影响条数为一条，可以通过DB.findAll('user')获取全部数据查看是否被删除成功  \n  \n//数据库中所有数据  \n//[{\"username\":\"张三\",\"sex\":\"男\",\"birthday\":{\"year\":2000,\"month\":6,\"day\":18}},{\"username\":\"李红\",\"sex\":\"女\",\"birthday\":{\"year\":1991,\"month\":9,\"day\":22}}]  \n```\n\njsonDB的高级应用示例：\n-------------------\n```javascript\n//向数据表插入一条数据\nDB.table('user').add({username:'王帅',sex:'男',birthday:{year:1995,month:10,day:23}});\n\t\t\t\n//查询所有人出生日期，并按出生年排序，由于之前使用table('user')定义为user表，所以可以省略，table方法定义是一直有效的，除非是重新设定了\nvar result = DB.field('username,birthday').order('birthday.year').select();\n//查询结果\t[{\"username\":\"李红\",\"birthday\":{\"year\":1991,\"month\":9,\"day\":22}},{\"username\":\"王帅\",\"birthday\":{\"year\":1995,\"month\":10,\"day\":23}},{\"username\":\"张三\",\"birthday\":{\"year\":2000,\"month\":6,\"day\":18}}]\n\n//先插入一些数据，方便后面的检索操作\nDB.table('user').add({username:'李亨',sex:'男',birthday:{year:2008,month:8,day:8}})\n.add({username:'张琦',sex:'男',birthday:{year:1990,month:10,day:23}})\n.add({username:'李媛芳',sex:'女',birthday:{year:1985,month:2,day:28}})\n.add({username:'李果果',sex:'女',birthday:{year:2002,month:3,day:15}})\n.add({username:'张源',sex:'男',birthday:{year:2005,month:12,day:5}})\n.add({username:'王丽娜',sex:'女',birthday:{year:1992,month:5,day:12}});\n\n//高级查询之模糊搜索\n//查询所有李姓成员(正则查找法)\nvar result = DB.field([\"username\"]).where('username.match(/^李/)').select();\n//查询结果[{\"username\":\"李红\"},{\"username\":\"李亨\"},{\"username\":\"李媛芳\"},{\"username\":\"李果果\"}]\n\n//查询所有李姓成员(字符串搜索法)\nvar result = DB.field([\"username\"]).where('username.indexOf(\"李\")=0').select();\n//查询结果[{\"username\":\"李红\"},{\"username\":\"李亨\"},{\"username\":\"李媛芳\"},{\"username\":\"李果果\"}]\n\n//查询所有在1990年到1995年出生的人\nvar result = DB.field([\"username\",\"birthday\"]).where('birthday.year\u003e=1990 and birthday.year\u003c=1995').order('birthday.year').select();\n//查询结果：[{\"username\":\"张琦\",\"birthday\":{\"year\":1990,\"month\":10,\"day\":23}},{\"username\":\"李红\",\"birthday\":{\"year\":1991,\"month\":9,\"day\":22}},{\"username\":\"王丽娜\",\"birthday\":{\"year\":1992,\"month\":5,\"day\":12}},{\"username\":\"王帅\",\"birthday\":{\"year\":1995,\"month\":10,\"day\":23}}]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkeridea%2Fjsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkeridea%2Fjsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkeridea%2Fjsondb/lists"}