Skip to content

Latest commit

 

History

History
96 lines (63 loc) · 1.55 KB

README.md

File metadata and controls

96 lines (63 loc) · 1.55 KB

Installation

WIP

Usage

# Create your models

import { Model } from 'expo-orm'

export default class Post extends Model {
  table = 'posts'

  fillable = ['title', 'body']
}

You need to specify the table property as it will be used to query the
database. The fillable property should also be defined because it
will be used in insert and update operations.

# Interacting with your model

Fetch a list of your models

const posts = await Post.get()

Get only the first item from the results

const post = await Post.first()

const archivedPost = await Post
  .where('archived_at', '!=', null)
  .first()

Find a specific model

const post = await Post.find(1)

Filtering the model

const draftedPosts = await Post
  .where('published_at', '=', null)
  .get()

const publishedPosts = await post
  .where('published_at', '!=', null)
  .get()

Updating models

await Post.where('id', '=', 1).update({ published_at: new Date() })

Deleting models

await Post.where('published_at', '=', null).delete()

# Using the Query Builder

In most cases it's recommended to use a Model but when you're not, you can:

import { Database } from 'expo-orm'

...

const db = Database.connect()
const posts = await db.table('posts').get()

Examples

Testing

yarn test

License

The MIT License (MIT). Please see License File for more information.