JSORM the isomorphic, framework-agnostic Javascript ORM

Filtering

Use #where() to apply filters:

Post.where({ important: true }).all()

/posts?filter[important]=true

#where() clauses can be chained together. If the same key is seen twice, it will be overridden:

Post
  .where({ important: true })
  .where({ ranking: 10 })
  .where({ important: false })
  .all()

/posts?filter[important]=false&filter[ranking]=10

#where() clauses are based on server implementation. The key should be exactly as the server understands it. Here are some common conventions we promote:

// id greater than 5
Post.where({ id_gt: 5 }).all()

// id greater than or equal to 5
Post.where({ id_gte: 5 }).all()

// id less than 5
Post.where({ id_lt: 5 }).all()

// id less or equal to 5
Post.where({ id_lte: 5 }).all()

// title starts with "foo"
Post.where({ title_prefix: "foo" }).all()

// OR these two values
Post.where({ status_or: ['draft', 'review'] }).all()

// AND these two values (default)
Post.where({ status: ['draft', 'review'] }).all()

// with special characters
Post.where({ title: '{{ Penn & Teller }}' }).all()