Document most methods and options in README

This commit is contained in:
Scott Kyle 2015-11-04 18:04:08 -08:00
parent 7b9831c70a
commit cdabc628be
1 changed files with 53 additions and 0 deletions

View File

@ -90,6 +90,59 @@ const realm = new Realm({schema: [Person]});
You can see more examples of how to use these APIs in the [ReactExample](https://github.com/realm/realm-js/tree/master/examples/ReactExample) app and in the [JS test files](https://github.com/realm/realm-js/tree/master/tests).
## Documentation
### `Realm` Constructor Options
- `path` defaults to `Realm.defaultPath` (which initially is `'Documents/default.realm'`)
- `schema` array of object type definitions (see below, optional if realm already created)
- `schemaVersion` defaults to `0` (should be incremented after changing the schema)
### Object Types
- `name` string used to refer to this object type
- `primaryKey` optional name of `STRING` or `INT` property that should be unique
- `properties` array of property defitions (see below)
### Property Types
When definining object `properties` in a `schema`, each should have a unique `name`, and the `type` of each property must be defined as either the name of an object type in the same schema **or** as one of the following:
- `Realm.Types.BOOL`
- `Realm.Types.INT`
- `Realm.Types.FLOAT`
- `Realm.Types.DOUBLE`
- `Realm.Types.STRING`
- `Realm.Types.DATE`
- `Realm.Types.DATA`
- `Realm.Types.OBJECT` (requires `objectType`, is always `optional`)
- `Realm.Types.LIST` (requires `objectType`, is never `optional`)
You _may_ specify these property options as well:
- `default` default value when property was not specified on creation
- `optional` boolean indicating if this property may be assigned `null` or `undefined`
### `Realm` Instance Methods
#### `create(type, props, update)`
- `type` string matching object `name` in the `schema` definition
- `props` object with property values for all required properties without a default value
- `update` optional boolean signaling that an existing object (matching primary key) should be updated
- _Returns a new realm object instance_
#### `delete(object)`
- `object` realm object or array of realm objects (which can be a `List` or `Results` object)
#### `deleteAll()`
**WARNING:** This does what you think it does!
#### `objects(type, query)`
- `type` string matching object `name` in the `schema` definition
- `query` optional string that defines a query to filter results (see tests for examples)
- _Returns `Results` object_
#### `write(callback)`
- `callback` function that is synchronously called inside the write transaction
#### `close()`
**WARNING:** This is only for advanced use cases and generally doesn't need to be used.
## License
Copyright 2015 Realm Inc - All Rights Reserved
Proprietary and Confidential