Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Last active April 18, 2017 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelnewton/69a1808ca085b392cafec59f969e59bb to your computer and use it in GitHub Desktop.
Save davelnewton/69a1808ca085b392cafec59f969e59bb to your computer and use it in GitHub Desktop.
Realm Sample
class Car {
static schema = {
name: 'Car',
properties: {
make: 'string',
model: 'string',
miles: 'int'
}
}
}
class Person {
static schema = {
name: 'Person',
properties: {
name: {type: 'string'},
cars: {type: 'list', objectType: 'Car'},
picture: {type: 'data', optional: true}
}
}
}
const realm = new Realm({ schema: [Car, Person] })
realm.write(() => {
let myCar = realm.create('Car', {
make: 'Honda',
model: 'Civic',
miles: 1000
})
myCar.miles += 20
})
const cars = realm.objects('Car').filtered('miles > 1000')
cars.length // => 1
realm.write(() => {
let myCar = realm.create('Car', {
make: 'Ford',
model: 'Focus',
miles: 2000
})
})
// Query results are updated in realtime
cars.length // => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment