JavaScript database Taffydb Usage Example Analysis _javascript skills

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.