utopia_database 0.3.0 copy "utopia_database: ^0.3.0" to clipboard
utopia_database: ^0.3.0 copied to clipboard

A light and easy to get started database library for all your Dart projects

Utopia Database #

Utopia Database is light and fast database library for Dart. It is designed to be simple and easy to use. It currently supports only MariaDB database but you can contribute to add adapters to other databases.

Setup #

Together with this package, you need to also add a database adapter package to your project. Check out MariaDB adapter package.

Example #

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('_myproject');
  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('users collection created');
  }
}

Contribute new adapter #

To add new adapter for different database, follow the steps in add database adapter.

2
likes
160
pub points
0%
popularity

Publisher

verified publisherappwriters.dev

A light and easy to get started database library for all your Dart projects

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, uuid

More

Packages that depend on utopia_database