-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd62dbf
commit f704518
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters