Insert & Query
Add records to collections and query them with filters, ordering, and pagination.
Insert a record
Pass any JSON-serialisable map. The returned record includes the auto-generated id, created_at, and created_by.
final record = await Koolbase.db.insert(
collection: 'posts',
data: {
'title': 'My first post',
'body': 'Hello from Koolbase',
'published': true,
'tags': ['flutter', 'mobile'],
},
);
print(record.id); // UUID
print(record.createdAt); // DateTime
print(record.data); // the JSON you insertedInsert or update in one call
You may supply your own id inside data: a valid UUID is kept as the record's $id, so the id you chose is the id you get back — this is how the SDKs give offline-created records an identity that survives sync. Anything that is not a UUID is silently ignored and the server generates one, so if the id you sent matters, send a UUID.
Get all records
Fetch all records in a collection. Returns up to 20 records by default.
final result = await Koolbase.db.collection('posts').get();
for (final record in result.records) {
print(record.data['title']);
}
print(result.total); // total count in collectionQuery with filters
Filter records by field values — .where() in Flutter, filters in React Native and on the web. Several filters are combined with AND.
// Filter by a single field
final published = await Koolbase.db
.collection('posts')
.where('published', isEqualTo: true)
.get();
// Filter by several fields: chain them
final filtered = await Koolbase.db
.collection('posts')
.where('published', isEqualTo: true)
.where('category', isEqualTo: 'flutter')
.get();Limit and offset
// First 10 records
final page1 = await Koolbase.db
.collection('posts')
.limit(10)
.get();
// Next 10
final page2 = await Koolbase.db
.collection('posts')
.limit(10)
.offset(10)
.get();Order results
// Newest first
final recent = await Koolbase.db
.collection('posts')
.orderBy('created_at', descending: true)
.limit(20)
.get();Get a single record
final record = await Koolbase.db.doc('record-uuid-here').get();
print(record.data['title']);Access rules apply
authenticated, the user must be logged in. If owner, only records created by the current user are returned.