# react-native-realm-query

> react native realm query

Latest version **0.3.2** (published 2025-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-realm-query
pnpm add react-native-realm-query
yarn add react-native-realm-query
bun add react-native-realm-query
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2025-06-11 |
| First published | 2023-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.0.0 |
| Dependencies | 0 |
| Unpacked size | 153.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Amir Valibeigi |
| Maintainers | amir_valibeigi |
| Keywords | react-native, ios, android, realm |

## Links

- npm: https://www.npmjs.com/package/react-native-realm-query
- Repository: https://github.com/rhv79/react-native-realm-query
- Homepage: https://github.com/rhv79/react-native-realm-query#readme
- Issues: https://github.com/rhv79/react-native-realm-query/issues
- npm.io page: https://npm.io/package/react-native-realm-query

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2025-06-11
- 0.3.1 — 2023-05-30
- 0.3.0 — 2023-03-21
- 0.2.0 — 2023-03-19

## README

# react-native-realm-query

realm query

## Installation

```sh
npm install react-native-realm-query
```

## Usage query builder

```js
import QueryBuilder, { setRealm } from 'react-native-realm-query';

// ...

setRealm(DATABASE); //for base model

console.log(new QueryBuilder(SCHEMA_NAME).get());
```

> [{...},{...},{...}]

## Usage base model

```js
import { ModelRelationship } from 'react-native-realm-query';
import { BRAND_SCHEMA } from '@tables/BrandTable';
import { CATEGORY_SCHEMA } from '@tables/CategoryTable';

interface BrandModelType {
  //...
}

export default class BrandModel extends ModelRelationship<BrandModelType> {
  constructor(json: BrandModelType) {
    super();
    this.id = json.id;
    this.title = json.title;
    //...
  }

  categories() {
    return this.hasMany(CATEGORY_SCHEMA);
  }
}

BrandModel.getTable = () => BRAND_SCHEMA;
```

```js
import BrandModel from '@models/BrandModel';

const brands = BrandModel.get().map((pB) => new BrandModel(pB));

console.log(brands);
console.log(brands[0].categories());
```

> [{id:1,title:'samsung'},{...},{...}]

> [{id:1,brand_id:1,title:'phone'},{...},{...}]

---

## Query Builder Methods

- and
- avg((keyof T | string)?)
- count((keyof T | string)?)
- find(id, property?)
- findOr(id, value, property?)
- findOrFail(id)
- first
- firstOr(value)
- firstOrFail
- get
- getQuery
- groupEnd
- groupStart
- limit(count, offset)
- offset(offset)
- or
- orWhere(WhereType | keyof T | string, WhereOperatorType?, WhereValueType?)
- orWhereBetween(property, a, b)
- orWhereEnd(property, text)
- orWhereRaw(query)
- orWhereStart(property, text)
- orWhereType(property: keyof T | string, value: ValueType | string | (ValueType | string)[] | number)
- sort(property, ASC | DESC)
- sum((keyof T | string)?)
- when(value?, (queryBuilder, value) => void)
- where(WhereType | keyof T | string, WhereOperatorType?, WhereValueType?)
- whereBetween(property, a, b)
- whereEnd(property, text)
- whereRaw(query)
- whereStart(property, text)
- whereType(property: keyof T | string, value: ValueType | string | (ValueType | string)[] | number)
- withBelongTo(schemaName,WithOption)
- withBelongToMany(schemaName,WithOption)
- withHasMany(schemaName,WithOption)
- withHasOne(schemaName,WithOption)

#### WithOption

- ownerProperty? keyof T | string
- childProperty? keyof P | string
- mapTo?: new (json:any) => P

#### WhereType

- property: string
- operator?: WhereOperatorType
- value: WhereValueType

#### WhereOperatorType

'!' | '!=' | '<' | '<=' | '<==' | '<>' | '=' | '==' | '>' | '>=' | '>==' | 'BEGINSWITH' | 'BEGINSWITH[c]' | 'CONTAINS' | 'CONTAINS[c]' | 'ENDSWITH' | 'ENDSWITH[c]' | 'LIKE' | 'LIKE[c]'

#### WhereValueType

string | number | (string | number)[] | null | undefined

---

## Base Model methods

- belongTo(schema, childProperty? = 'id', ownerProperty?)
- belongToMany(schema, ownerProperty? = 'id', childProperty?)
- hasMany(schema, ownerProperty? = 'id', childProperty?)
- hasOne(schema, ownerProperty? = 'id', childProperty?)
- static avg
- static count
- static find
- static findOr
- static findOrFail
- static first
- static firstOr
- static firstOrFail
- static get
- static getTableName
- static sum
- static when
- static where
- static whereBetween
- static whereEnd
- static whereStart
- static whereType

---

## next version

- whereHas

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

---
_Source: https://npm.io/package/react-native-realm-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
