utopia_database 0.2.0 utopia_database: ^0.2.0 copied to clipboard
A light and easy to get started database library for all your Dart projects
example/utopia_database_example.dart
import 'dart:io';
import 'package:utopia_database/utopia_database.dart';
import 'package:utopia_database_adapter_mariadb/utopia_database_adapter_mariadb.dart';
void main() async {
final mariadb = await MariaDB.init(
host: 'localhost', port: 3306, user: 'user', password: 'password');
final database = Database(mariadb);
print('connection initialized');
database.setDefaultDatabase('applications');
database.setNamespace('_console');
print('namesapace set');
final exists = await database.exists(collection: Database.metadata);
if (!exists) {
await database.create();
print('metadata created');
}
final userExists = await database.exists(collection: 'users');
if (!userExists) {
await database.createCollection('users', [
Attribute(
id: 'name',
type: Database.varString,
isRequired: true,
size: 255,
),
Attribute(
id: 'email',
type: Database.varString,
isRequired: true,
size: 255,
),
Attribute(
id: 'description',
type: Database.varString,
isRequired: true,
size: 2550,
),
], []);
print('collection created');
}
// final attr1 = await database.createAttribute(
// 'users',
// Attribute(
// id: 'publishedDate',
// type: Database.varDateTime,
// isRequired: false,
// signed: true,
// array: false));
// print('attribute added');
// final attr = await database.createAttribute(
// 'users',
// Attribute(
// id: 'age',
// type: Database.varInteger,
// isRequired: false,
// signed: false,
// array: false));
// print('attribute added');
// final doc = await database.updateDocument(
// 'users',
// '329355fd-6302-4d7f-bd4c-38b73e577f1b',
// Document({
// '\$id': '329355fd-6302-4d7f-bd4c-38b73e577f1b',
// 'age': 25,
// 'publishedDate': DateTime.now(),
// }));
print('document created');
final result = await database.find('users', [
Query.or([
Query.greaterThan('age', 25),
Query.between('name', 'a', 'i'),
]),
Query.select(['name', 'age', '\$id', '\$createdAt', '\$updatedAt']),
]);
print(result);
exit(0);
}