harndb 0.1.6 harndb: ^0.1.6 copied to clipboard
a simple key-value non-relational database engine for dart.
import 'package:flutter/material.dart';
import 'package:harndb/harnlog.dart';
import 'package:harndb_example/data.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
db.initialize();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
harnLog.setCallback((p0) => print(p0));
}
void deleteCollections() async {
// final list = await db.listCollectionNames();
// list.forEach((element) {
// db.deleteCollection(element);
// print(element);
// });
}
void test() async {
int i = 0;
print(users.find().length);
while (i < 500) {
User firstUser = User(id: "id$i", name: "Andress", age: 33);
await users.insert(firstUser);
i++;
}
final all = users.find();
print("se ejecuta");
while (i < all.length) {
final e = all[i];
e.name = "${e.name}-$i";
await users.update(e.id, e);
print("ok");
i++;
}
int o = 0;
while (o < all.length) {
print(all[o].name);
o++;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
Container(
height: 20,
),
ElevatedButton(onPressed: test, child: const Text("test")),
Container(
height: 20,
),
ElevatedButton(
onPressed: () async {
final a = await db.listCollectionNames();
a.forEach((element) {
db.deleteCollection(element);
});
},
child: const Text("delete")),
],
),
),
);
}
}