realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.77k stars 573 forks source link

Document query placeholder syntax #510

Closed alazier closed 7 years ago

alazier commented 8 years ago

Would have helped with #500

astigsen commented 8 years ago

In general it seems like we could use a bit more detailed documentation about the query syntax. The cheatsheet at https://realm.io/news/nspredicate-cheatsheet/ is useful but contains lot of references to Cocoa that may be confusing for js users.

appden commented 8 years ago

Definitely agree with what @alazier said. We do have the query placeholder syntax documented in the filtered method documentation, but that's pretty much it.

mehraj43 commented 2 years ago

can anyone please tell me what $0 means in this : this.state.subdivisions.filtered('subdivisionName CONTAINS[c] $0', this.state.nameFilter);

mehraj43 commented 2 years ago

and what does [0] means is it for specifying array positions or something else and will be real help full if you could suggest me any tutorials or materials for Realm react native

takameyer commented 2 years ago

@mehraj43 The $n stands for the nth argument (0 based) after the given query string. For example:

"progressMinutes > $0 AND assignee == $1", 15, "Bart"

$0 is 15 $1 is "Bart"

I'll break down this specific example this.state.subdivisions.filtered('subdivisionName CONTAINS[c] $0', this.state.nameFilter);

This query is asking if the subdivisionName CONTAINS the value of this.state.nameFilter within itself (similar to the JavaScript string method includes). The [c] denotes that this check is case insensitive ("FooBar" CONTAINS[c] "oba" is true and "FooBar" CONTAINS "oba" is false)

There are many more examples of the Realm Query Language on this page: https://www.mongodb.com/docs/realm/realm-query-language/

RQL is based on a subset of NSPredicate. If the documentation is missing something, google searches for NSPredicate can also lead you in the right direction.

mehraj43 commented 2 years ago

Thanks man for the help

mehraj43 commented 2 years ago

const realm = new Realm({ path: 'UserDatabase.realm', schema: [ { name: 'user_details', properties: { user_id: {type: 'int', default: 0}, user_name: 'string', user_contact: 'string', user_address: 'string', }, }, ], });

can anyone explain me what does path mean in this and how to delete the schema if created

mehraj43 commented 2 years ago

and does realm not generate object id like mongodb and how to create one if it cant generate and how to autoincrement it

tomduncalf commented 2 years ago

@mehraj43 Realm does not generate object IDs automatically, you don't necessarily need an id field on your Realm objects if you don't want, but to create one you can use the BSON module like so:

import { BSON } from "realm";

// ...

realm.create({
  id: new BSON.ObjectId()
  // ...
})
tomduncalf commented 2 years ago

@mehraj43

can anyone explain me what does path mean in this and how to delete the schema if created

The path indicates the name of the Realm file that will be created on disk (e.g. in the working directory on Node or in the app's documents folder on mobile) – this is where your data is actually stored. You can delete the Realm file by calling Realm.deleteFile(config), where config if the configuration you used to open the Realm (so in your example, you'd want to extract the config into a variable so you can reuse it). Of course you can also just delete the files manually.

Please could you open a new issue if you have problems that are not related to this (closed) issue?

mehraj43 commented 2 years ago

i tried using realm in drawer navigation but my app keeps crashing so i installed realm@hermes through yarn now im getting this error Error: Exception in HostObject::get(propName:Realm): std::bad_alloc