Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Mar 14, 2024
1 parent dd62dbf commit f704518
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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.

## Getting started

Add the following to your `pubspec.yaml` file:

```yaml
dependencies:
utopia_database: <latest>
utopia_database_adapter_mariadb: <latest>
```
## Usage
```dart
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](/utopia_database/doc/add_database_adapter.md).
4 changes: 2 additions & 2 deletions utopia_database/doc/add_database_adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Every database adapter is a separate package. To create a adapter for new databa

## Create package

Fork the repository and clone it to your local machine. Then create a new Dart package using the following command.

The naming pattern for the database adapter package is `utopia_database_adapter_<database_name>`. For example, the MariaDB adapter package is `utopia_database_adapter_mariadb`.

```bash
Expand All @@ -28,5 +30,3 @@ class <DatabaseName> extends Adapter {
// implement the abstract methods
}
```

> If you want the adapter to be a part of utopia-dart ecosystem, please raise a issue and share your repo URL and we will review and create a repo under utopia-dart organization.

0 comments on commit f704518

Please sign in to comment.