First, JSONDB
:Https://github.com/ThinkerCodeChina/jsonDB
JSONDB is a class library of JS that implements the use of SQL statements to modify JSON data and additions and deletions.
The JSONDB is built from an application requirement of HTML5 local storage, which can be used to add and revise JSON data through SQL, and the library provides the basic functions of the database such as where retrieval condition, data sorting, limit query condition restriction and so on.
With Jsondb, you can easily maintain a library/table or multiple libraries/tables, without the need for additional JSON data maintenance, to simplify SQL operations after the class library is perfected, and to extend the coherent operation model based on the JSONDB core module, simplifying the operation of JSONDB and the probability of an error in the SQL statement.
Second, the current version of the deficiencies:
Three, JSONDB basic application Example:
1 //Create a User data table and define a db jsondb alias2 vardata = [{username: ' Zhang San ', Sex: ' Male ', birthday:{year:2000,month:6,day:18}},{username: ' Li Hong ', Sex: ' Female ', birthday:{year:1986, Month:9,day:22}}]; 3 //The following methods can get aliases in two ways, one from the Init method (recommended), and one to get the return value of the Jsondb () method4 //The alias operation data created by the Init () method will be used later in the example5 varJDB = jsondb (data, ' user '). Init (' DB ')); 6 7 //Insert a new piece of data8Data = {username: ' Li think ', Sex: ' Male ', birthday:{year:1990,month:2,day:15}}; 9Db.insert (data, ' user '); Ten One //Query the gender of the name Li Hong, where condition must plus () No person will be wrong A varResult =db.query (' Select Sex ' from User where (username= "Li Hong") '); - //Result: [{"Sex": "Female"}] - the //Inquiries were born 2000 years ago and sorted by year of birth - varResult =db.query (' select * from user where (birthday.year<2000) Order by birthday.year ASC '); - //results: [{"username": "Li Hong", "sex": "female", "birthday": {"Year": 1986, "month": 9, "Day": 22}},{"username": "Li Want", "sex": "Male", " Birthday ": {" Year ": 1990," Month ": 2," Day ": []}] - + //Check out the minimum age of two people - varResult =db.query (' SELECT * from user order by birthday.year desc limit 2 '); + //Query Results: [{"username": "Zhang San", "Sex": "Male", "birthday": {"Year": +, "month": 6, "Day": 18}},{"username": "Li Want", "sex": "Male", " Birthday ": {" Year ": 1990," Month ": 2," Day ": []}] A at //revised Li Hong's date of birth - varResult =db.query (' Update user set birthday.year=1991 where (username= "Li Hong") limit 1 '); - //The number of affected bars is one, you can get all the data through Db.findall (' user ') to see if it has been modified successfully - - //Delete the data named Li thought - varResult =db.query (' Delete from user where (username= "Li wants") limit 1 '); in //The number of affected bars is one, you can get all the data through Db.findall (' user ') to see if the deletion was successful. - to //all data in the database + //[{"username": "Zhang San", "Sex": "Male", "birthday": {"Year": +, "month": 6, "Day": 18}},{"username": "Li Hong", "sex": "Female", " Birthday ": {" Year ": 1991," month ": 9," Day ": $}]
Iv. Advanced Application examples for JSONDB:
1 //inserting a piece of data into a data table2Db.table (' user '). Add ({username: ' Wang Shuai ', Sex: ' Male ', birthday:{year:1995,month:10,day:23}});3 4 //querying the owner's date of birth and sorting by year of birth, as previously defined as the User table using table (' user '), can be omitted, the table method definition is always valid, unless it is re-set5 varresult = Db.field (' Username,birthday '). Order (' Birthday.year ')). Select ();6 //query results [{"username": "Li Hong", "birthday": {"Year": 1991, "month": 9, "Day": 22}},{"username": "Wang Shuai", "Birthday": {"Year" : 1995, "month": Ten, "Day": 23}},{"username": "Zhang San", "Birthday": {"Year": $, "month": 6, "Day": *}]7 8 //First, insert some data to facilitate the subsequent retrieval operations9Db.table (' user '). Add ({username: ' Li Hen ', Sex: ' Male ', birthday:{year:2008,month:8,day:8}})Ten. Add ({username: ' Zhang Qi ', Sex: ' Male ', birthday:{year:1990,month:10,day:23}}) One. Add ({username: ' Li Yuafang ', Sex: ' Female ', birthday:{year:1985,month:2,day:28}}) A. Add ({username: ' Ligougo ', Sex: ' Female ', birthday:{year:2002,month:3,day:15}}) -. Add ({username: ' Zhang Yuan ', sex: ' Male ', birthday:{year:2005,month:12,day:5}}) -. Add ({username: ' Wang Lina ', Sex: ' Female ', birthday:{year:1992,month:5,day:12}}); the - //Fuzzy search of advanced query - //query All members of the Li surname (regular lookup method) - varresult = Db.field (["username"]). WHERE (' Username.match (/^ Lee/) '). Select (); + //query result [{"username": "Li Hong"},{"username": "Li Hen"},{"username": "Li Yuafang"},{"username": "Ligougo"}] - + //query all members of Li Surname (string search method) A varresult = Db.field (["username"]). WHERE (' Username.indexof ("Lee") =0 '). Select (); at //query result [{"username": "Li Hong"},{"username": "Li Hen"},{"username": "Li Yuafang"},{"username": "Ligougo"}] - - //Check all people born from 1990 to 1995 - varresult = Db.field (["username", "Birthday"]). where (' birthday.year>=1990 and birthday.year<=1995 '). Order (' Birthday.year '). Select (); - //Query Result: [{"username": "Zhang Qi", "Birthday": {"Year": 1990, "month": Ten, "Day": 23}},{"username": "Li Hong", "birthday": {"Year" : 1991, "month": 9, "Day": 22}},{"username": "Wang Lina", "Birthday": {' Year ': 1992, ' Month ': 5, ' Day ': 12}},{"username": "Wang Shuai", " Birthday ": {" Year ": 1995," month ": Ten," Day ": +}]
Jquery implements JSON complex query operations (JSONDB)