Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Collections — Flutter SDK

class Post {
final String id;
final String title;
final String body;
Post({required this.id, required this.title, required this.body});
factory Post.fromJson(Map<String, dynamic> j) =>
Post(id: j['id'], title: j['title'], body: j['body']);
}
final posts = bunbase.collection('posts', Post.fromJson);
final result = await posts.list(const ListQuery(
sort: '-_created_at',
page: 1,
perPage: 20,
));
// result.items — List<Post>
// result.total — int (total count)
// result.page — current page
final post = await posts.get('rec_01J...');
// With relation expansion:
final post = await posts.get('rec_01J...', expand: ['author']);
final post = await posts.create({'title': 'Hello', 'body': 'World'});
final created = await posts.createMany([
{'title': 'Post A'},
{'title': 'Post B'},
]);
final updated = await posts.update('rec_01J...', {'title': 'Updated'});
await posts.delete('rec_01J...');
final restored = await posts.restore('rec_01J...');
final total = await posts.count();
// With filter:
final active = await posts.count(
filter: {'status': StringFilter('published')},
);

ListQuery(filter: {'status': StringFilter('active')})
ClassDart typeExample
StringFilterStringStringFilter('active')
IntFilterintIntFilter(42)
DoubleFilterdoubleDoubleFilter(3.14)
BoolFilterboolBoolFilter(true)
StringListFilterList<String>StringListFilter(['a','b'])
IntListFilterList<int>IntListFilter([1,2,3])

Use OpFilter with a map of operator → value:

ListQuery(filter: {
'age': OpFilter({
'gte': IntFilter(18),
'lt': IntFilter(65),
}),
})

Supported operators: eq, neq, gt, gte, lt, lte, in, nin, contains, startsWith.

ListQuery(search: 'flutter tutorial')

var page = 1;
while (true) {
final result = await posts.list(ListQuery(page: page, perPage: 50));
process(result.items);
if (result.items.length < 50) break;
page++;
}

Use these to subscribe to changes without hard-coding strings:

bunbase.realtime.subscribe(posts.channel, onEvent: (e) { ... }); // all changes
bunbase.realtime.subscribe(posts.mineChannel, onEvent: (e) { ... }); // auth user only
bunbase.realtime.subscribe(posts.recordChannel(id), onEvent: (e) { }); // single record
bunbase.realtime.subscribe(posts.recordsChannel, onEvent: (e) { ... }); // multi-record IDs