npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

realm-query

v0.0.7

Published

A query builder for realm.js

Downloads

550

Readme

CircleCI

Test Coverage

Code Climate


Realm Query

A query builder for realm.js inspired of Realm Java's query engine.

https://realm.io/docs/java/latest/#queries

Installation

$ npm install --save realm-query
# or
$ yarn add realm-query

Usage

const RealmQuery = require('realm-query');
const realm = new Realm({...});

// Way 1
let query = RealmQuery
  .create()
  .contains('name', 'phu', true)
  .in('id', [1001, 1002]);

// get objects
// query.toString() = name CONTAINS[c] "phu" AND (id == 1001 OR id == 1002)
let results = realm.objects('Person').filtered(query.toString());

// Way 2. use lib to get objects
let results = RealmQuery
                .where(realm.objects('Person'))
                .contains('name', 'phu', true)
                .in('id', [1001, 1002])
                .findAll()

// Complex query
let results = RealmQuery
                .where(realm.objects('Person'))
                .contains('name', 'phu', true)
                .beginGroup()
                  .in('id', [1001, 1002])
                  .or()
                  .between('age', 20, 45)
                .endGroup()
                .sort('id', 'DESC')
                .findAll()
// It will query like this
// name CONTAINS[c] "phu" AND ((id == 1001 OR id == 1002) OR (age >= 20 AND age <= 45))
// and sort by id desc

API

  • average(fieldName: string): number

    Returns the average of a given field

  • beginGroup(): RealmQuery

    Begin grouping of conditions ("left parenthesis")

  • beginsWith(fieldName: string, value: string, casing?: boolean): RealmQuery

    Condition that the value of field begins with the specified string

  • between(fieldName: string, from: number|date, to: number|date): RealmQuery

    Between condition

  • contains(fieldName: string, value: string, casing?: boolean): RealmQuery

    Condition that value of field contains the specified substring

  • count(): number

    Counts the number of objects that fulfill the query conditions

  • distinct(fieldName: string): Array

    Returns a distinct set of objects of a specific class.

  • endGroup(): RealmQuery

    End grouping of conditions ("right parenthesis") which was opened by a call to beginGroup()

  • endsWith(fieldName: string, value: string, casing?: boolean): RealmQuery

    Condition that the value of field ends with the specified string

  • equalTo(fieldName: string, value: string|number|boolean|date): RealmQuery

    Equal-to comparison

  • findAll(): ReamResults

    Finds all objects that fulfill the query conditions

  • findFirst(): Object

    Finds the first object that fulfills the query conditions

  • greaterThan(fieldName: string, value: number|date): RealmQuery

    Greater-than comparison

  • greaterThanOrEqualTo(fieldName: string, value: number|date): RealmQuery

    greater-than-or-equal-to comparison

  • in(fieldName: string, values: string|number[]): RealmQuery

    In comparison

  • lessThan(fieldName: string, value: number|date): RealmQuery

    Less-than comparison

  • lessThanOrEqualTo(fieldName: string, value: number|date): RealmQuery

    Less-than-or-equal-to comparison

  • max(fieldName: string): Object

    Finds the maximum value of a field

  • min(fieldName: string): Object

    Finds the miniimum value of a field

  • not(): RealmQuery

    Negate condition

  • notEqualTo(fieldName: string, value: string|number|boolean|date): RealmQuery

    Not-equal-to comparison

  • and(): RealmQuery

    AND logic operator. Use in group

  • or(): RealmQuery

    OR logic operator. Use in group

    let results = RealmQuery
          .where(realm.objects('Person'))
          .contains('name', 'phu', true)
          .beginGroup()
            .in('id', [1001, 1002])
            .or()
            .between('age', 20, 45)
          .endGroup()
          .findAll()
  • sum(): number

    Calculates the sum of a given field

  • sort(fieldName: string, order?: 'ASC' | 'DESC'): RealmQuery

    Set sorted into realm.objects

  • join(query: RealmQuery): RealmQuery

    Join queries

    let query1 = RealmQuery
      .where(realm.objects('Person'))
      .in('id', [1001, 1002])
    let query2 = RealmQuery
      .where(realm.objects('Person'))
      .greaterThan('age', 25);
    query1.join(query2);
      
    query1.toString = (id == 1001 OR id == 1002) AND age > 25
  • where(objects?: RealmResults): RealmQuery

    Create new query

  • create(objects?: RealmResults): RealmQuery

    Create new query. Alias of where


Changelog

License