[Node.js] Use Realm Object Database with Node.js
Realm is an ACID compliant object database. In this lesson, you will learn how to install Realm, define schemas for your data, perform CRUD operations and persist your data to the filesystem.
var Realm = require('realm');
const PetShema = {
name: 'Pet',
properties: {
name: 'string',
species: 'string',
age: 'int',
hasFur: 'bool'
}
};
const PersonSchema = {
name: 'Person',
primaryKey: 'id',
properties: {
id: 'int',
name: 'string',
birthday: 'date',
pet: {type: 'Pet'}
}
};
let realm = new Realm({
path: './people.realm',
schema: [PetShema, PersonSchema]
});
realm.write(() => {
realm.create('Person', {
id: ,
name: 'Bpb',
birthday: new Date('2001-10-10'),
pet: {
name: 'Fluffy',
species: 'Cat',
age: ,
hasFur: true
}
})
});
realm.write(() => {
realm.create('Person', {
id: ,
name: 'Tom',
birthday: new Date('1989-12-17'),
pet: {
name: 'Umi',
species: 'Dog',
age: ,
hasFur: true
}
});
});
let people = realm.objects('Person');
let pets = realm.objects('Pet');
console.log("people", JSON.stringify(people, null, ));
console.log("pets", JSON.stringify(pets, null, ));
let filteredPets = pets.filtered('age < 5');
console.log("filteredPets", JSON.stringify(filteredPets, null, ));
let multiFilterPets = pets.filtered('hasFur = true AND name BEGINSWITH "F"');
console.log("multiFilterPets", JSON.stringify(multiFilterPets, null, ));
let sortedAge = pets.sorted('age');
console.log("sortedAge", JSON.stringify(sortedAge, null, ));
// Overwrite the existing Person
realm.write(() => {
realm.create('Person', {id: , name: 'Jake'}, true)
});
console.log("Person", JSON.stringify(people, null, ));
// delete
let person = realm.objects('Person').filtered('id = 0');
realm.write(() => {
realm.delete(person);
});
console.log("After delete", JSON.stringify(people, null, ));
The data is stored in the local files:

[Node.js] Use Realm Object Database with Node.js的更多相关文章
- react,react native,webpack,ES6,node.js----------今天上午学了一下node.js
http://www.yiibai.com/nodejs/node_install.html---node.js具体入门资料在此 Node JS事件循环 Node JS是单线程应用程序,但它通过事件和 ...
- Node.app – 用于 iOS App 开发的 Node.js 解释器
Node.app 是用于 iOS 开发的 Node.js 解释器,它允许最大的代码重用和快速创新,占用资源很少,为您的移动应用程序提供 Node.js 兼容的 JavaScript API.你的客户甚 ...
- JS一般般的网页重构可以使用Node.js做些什么(转)
一.非计算机背景前端如何快速了解Node.js? 做前端的应该都听过Node.js,偏开发背景的童鞋应该都玩过. 对于一些没有计算机背景的,工作内容以静态页面呈现为主的前端,可能并未把玩过Node.j ...
- nw.js桌面程序自动更新(node.js表白记)
Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...
- node源码详解(三)—— js代码在node中的位置,process、require、module、exports的由来
本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/nodesource3 本博客同步在https://cnodejs.o ...
- node.js 之 Hello,World in Node !
创建一个js文件,把下面的内容粘贴进去,命名为helloworld.js. //加载 http 模块 var http = require("http"); //创建 http 服 ...
- Node.js学习(第一章:Node.js安装和模块化理解)
Node.js安装和简单使用 安装方法 简单的安装方式是直接官网下载,然后本地安装即可.官网地址:nodejs.org Windows系统下,选择和系统版本匹配的.msi后缀的安装文件.Mac OS ...
- Node.js实战项目学习系列(5) node基础模块 path
前言 前面已经学习了很多跟Node相关的知识,譬如开发环境.CommonJs,那么从现在开始要正式学习node的基本模块了,开始node编程之旅了. path path 模块提供用于处理文件路径和目录 ...
- [Node.js] 00 - Where do we put Node.js
Ref: 前后端分离的思考与实践(五篇软文) 其实就是在吹淘宝自己的Midway-ModelProxy架构. 第一篇 起因 为了提升开发效率,前后端分离的需求越来越被重视, 同一份数据接口,我们可以定 ...
随机推荐
- ArcSDE:C#创建SDE要素数据集
转自原文 ArcSDE:C#创建SDE要素数据集 /// <summary> /// 判断指定数据集是否存在 /// </summary> /// <param name ...
- worktools-不同分辨率下图片移植
1.下载需要移植的平台代码 1)查看手机需要的项目平台信息:adb shell getprop | gerp flavor ----->mt6732_m561_p2_kangjia_cc ...
- C#截取指定长度中英文字符串方法 (修改)
public static string GetFirstString(string stringToSub, int length) { Regex regex = new Regex(" ...
- golang filepath.Glob
package main import ( "fmt" "path/filepath" ) func main() { //找出/home/ 目录下的所有的lo ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-1/2
原文地址: http://blog.csdn.net/cocos2der/article/details/51006463 本文主要讲述了如何使用Multiplayer Networking开发多人游 ...
- Method of address space layout randomization for windows operating systems
A system and method for address space layout randomization ("ASLR") for a Windows operatin ...
- android studio执行 Information:Gradle tasks [:app:assembleDebug]失败处理
Error:Execution failed for task ‘:app:mergeDebugResources’. > Some file crunching failed, see log ...
- node.js服务器核心http和文件读写
使用htpp给客服端的数据,把数据交给浏览器渲染.利用 http创建服务器,如客户端请求为:127.0.0.1:3000或127.0.0.1:3000/xxx.html时 ,判断www文件夹中,文件 ...
- Android Material风格的应用(一)--AppBar TabLayout
打造Material风格的Android应用 Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerV ...
- 关于http请求指定本地ip
static void Main(string[] args) { //ssl证书验证问题(没有校验) ServicePointManager.ServerCertificateValidationC ...