Last active
April 18, 2017 21:18
-
-
Save davelnewton/69a1808ca085b392cafec59f969e59bb to your computer and use it in GitHub Desktop.
Realm Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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