Giter VIP home page Giter VIP logo

realm-orm's Introduction

Realm-orm

Codacy Badge Codacy Badge

Simple orm for realm-js with query builder

Installation

npm

npm install realm-orm realm --save

yarn

yarn add realm-orm realm

Usage example

create your models

import Model from 'realm-orm/Model'

export default class Person extends Model {
  // realm schema
  static schema = {
    name: 'Person',
    primaryKey: 'id',
    properties: {
      id: 'int',
      name: 'string',
      hobbies: {
        type: 'string',
        optional: true
      },
      age: 'int',
      createdAt: 'date'
    }
  }
  // for model.searchText()
  static stringFields = ['name']
}

create a new db instance with realm option (path, schema, migration, etc...) and open it

import DB from 'realm-orm'
import Person from './models/Person'
realm = new DB({
  schema: [
    Person
  ]
});
realm.open().then(() => {
  // realm is ready
})

insert data in database (data can be array or object). If you insert object with same primary key realm update existing object

    Person.insert([{
      id: 1,
      name: 'second person',
      age: 16,
      createdAt: new Date(),
    }, {
      id: 2,
      name: 'third person',
      age: 96,
      createdAt: new Date(),
    }]);

get a record

person = Person.find(1)
// update person
person.update({ age: 10 })
// delete person
person.delete()
// or
Person.delete(person)

query model

let oldPeople = Person.query()
                  .greaterThan('age', 90)
                  .findAll();
// results can use query
oldPeople.query()

For more examples and usage, please refer to the doc.

Stuff used to make this

Release History

  • 1.0.0
    • initial version

Meta

Distributed under the MIT license. See LICENSE for more information.

https://github.com/artis-auxilium/realm-orm

Contributing

  1. Fork it (https://github.com/artis-auxilium/realm-orm/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

realm-orm's People

Contributors

d3v2a avatar raphaelbadia avatar

Watchers

 avatar  avatar

Forkers

ledouxvi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.