When you have your Collections defined, learn how to manipulate them!
Before you can do anything, you have to open an Isar instance. Each instance needs a directory with write permission.
You can use the default config or provide some of the following parameters.
|You can open multiple instances with distinct names. By default, |
|The storage location for this instance. You can pass a relative or absolute path. By default, |
|Sets the maximum instance size. The default is 1GB and you probably don't need to change it.|
|Optional 32 byte (256bit) key to encrypt the database|
You can either store the Isar instance in a global variable or use your favorite dependency injection package to manage it.
If an instance is already open, calling
openIsar() will yield the existing instance regardless of the specified parameters. That's useful for using isar in an isolate.
The Collection object is how you find, query, and create new records of a given type.
All your collections live in the Isar instance. Remember the
Contact class we annotated before with
@Collection(). You can get the contacts collection with:
That was easy!
get() returns a
Future. All Isar operations are asynchronous by default. Most operations have a synchronous counterpart:
Find a list of records matching given conditions using
➡️ Learn more: Queries
To create, update, or delete records, use the respective operations wrapped in a write transaction:
➡️ Learn more: Transactions
When an object is not yet managed by Isar, you need to
.put() it into a collection. If the id field is
null, Isar will assign an auto-increment id.
Both creating and updating works with
yourCollection.put(yourObject). If the id is null (or does not exist), the object is inserted, otherwise it is updated.