mirror of
https://github.com/hanzo-dart/base.git
synced 2026-09-11 18:41:29 +00:00
pub.dev names 'hanzo' and 'base' are taken by unrelated packages; 'hanzo_base' is the correct available name. Renames the library (lib/hanzo.dart -> lib/hanzo_base.dart), example, and test, and fixes all package: imports, README, badge, and pubspec repository to hanzo-dart/base. dart analyze --fatal-infos + dart test green; pub publish --dry-run clean (0 warnings).
30 lines
853 B
Dart
30 lines
853 B
Dart
import 'package:hanzo_base/hanzo_base.dart';
|
|
|
|
Future<void> main() async {
|
|
final base = HanzoBase('https://base.hanzo.ai');
|
|
|
|
// Authenticate against a Hanzo IAM-backed auth collection.
|
|
await base.collection('users').authWithPassword('[email protected]', 'secret');
|
|
|
|
// List records.
|
|
final page = await base.collection('posts').getList(
|
|
perPage: 20,
|
|
filter: base.filter('published = {:v}', {'v': true}),
|
|
sort: '-created',
|
|
);
|
|
for (final record in page.items) {
|
|
// ignore: avoid_print
|
|
print('${record.id}: ${record['title']}');
|
|
}
|
|
|
|
// Subscribe to realtime changes.
|
|
final unsubscribe = base.collection('posts').subscribe('*', (event) {
|
|
// ignore: avoid_print
|
|
print('${event.action}: ${event.record.id}');
|
|
});
|
|
|
|
// Later: stop listening and release resources.
|
|
unsubscribe();
|
|
base.close();
|
|
}
|