首页 > Javascript

TaffyDB – javascript数据库 - 懒人日记

你有没有注意到Javascript对象的字面量看起来很像一个数据库表?[ {"id":1,"gender":"M","first":"John","last":"Smith","city":"Se...

你有没有注意到Javascript对象的字面量看起来很像一个数据库表?

[    {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},    {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},    {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},    {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}    ]

TaffyDB是一个Javascript库,它提供了强大的数据库功能,大大改善了你在Javascript中使用数据的方式。

创建一个数据库

// Create DB and fill it with recordsvar friends = TAFFY([    {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},    {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},    {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},    {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}    ]);

使用字段名或者字段的关系过滤

// Find all the friends in Seattlefriends({city:"Seattle, WA"});// Find John Smith, by IDfriends({id:1});// Find John Smith, by Namefriends({first:"John",last:"Smith"});

很容易访问数据

// Kelly's recordvar kelly = friends({id:2}).first();// Kelly's last namevar kellyslastname = kelly.last;// Get an array of record idsvar cities = friends().select("id");// Get an array of distinct citiesvar cities = friends().distinct("city");// Apply a function to all the male friendsfriends({gender:"M"}).each(function (r) {   alert(r.name + "!");});

快速地修改数据

// Move John Smith to Las Vegasfriends({first:"John",last:"Smith"}).update({city:"Las Vegas, NV:"});// Remove Jennifer Gill as a friendfriends({id:4}).remove();// insert a new friendfriends.insert({"id":5,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"});

更多文档:http://www.taffydb.com/workingwithdata

本文由用户 【admin】 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。

转载本站原创文章,请注明出处,并保留原始链接、图片水印。

本站是一个以用户分享为主的开源技术平台,欢迎各类分享!

本文地址:http://www.mj85.com/javascript/264.html

分享:

上一篇:Detect CSS3 Support in Browsers with JavaScript - 懒人日记

下一篇:已经是最后一篇

评论 [共0条评论]

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

您现面为匿名用户,暂不能发表评论。如想评论则请登录注册

相关内容

发布者

管理员 发于:

19年/05月/27日 05时

查看次数: 389

标签 Tags

无标签

谁收藏了?

0人已收藏