This example describes the use of JavaScript database Taffydb. Share to everyone for your reference. Specifically as follows:
Taffydb is a free and open source JavaScript Library for implementing a lightweight data access layer on the WEB, a simple database.
Data definition:
var friends = new Taffy (
[
{name: "Bob",
Gender: "M",
married: "No",
age:25, State
: "NY",
favorite_foods:["Pizza", "Tacos"]},
{name: "Joyce",
Gender: "F",
married: "No",
age:29,
State: "WA",
favorite_foods:["salad", "cheese Sticks"]},
{name: "Dan",
Gender: "M",
married: "No ",
age:29, State
:" MT ",
favorite_foods:[" pizza "," hamburgers "," BLTs "]},
{name:" Sarah ",
Gender: "F",
married: "No",
age:21, State
: "ID",
favorite_foods:["pizza", "Sushi"}
]
)
Inquire:
Friends.find ({age:{greaterthan:22}});
Friends.find ({state:["WA", "MT", "ID"]});
Friends.find ({state:["WA", "MT", "ID"],
age:{greaterthan:22});
Update action:
Friends.update (
{State
: "CA",
married: "Yes"
},
{
name: "Joyce"
}
);
Friends.update ({state: "CA", married: "Yes"},1);
Friends.update (
{State
: "CA",
married: "Yes"
},
Friends.find (
{name: "Joyce"}
)
);
Insert data:
Inserting is simple and works as your would expect:
Friends.insert (
{name: "Brian",
Gender: "M",
Married: "No",
age:52, State
: "FL",
favorite_foods:["fruit", "steak"]
};
Delete:
Copy Code code as follows:
Friends.remove ({name: "Brian"});
Sort:
Friends.orderby (["Age", {"name": "DESC"}]);
var keys = new Taffy ([
{name: "12abc"},
{name: "abc343"},
{name: "1abc"},
{name: "23ABC"}
]);
Keys.orderby ({name: "logical"});
foreach Usage:
Friends.foreach (function (f,n) {alert (f.name)});
Friends.foreach (
function (f,n) {alert (f.name);},
{favorite_foods:{has: "Pizza"}}
);
I hope this article will help you with your JavaScript programming.