Skip to content

schultek/stormberry

Repository files navigation

Stormberry


Astrongly-typed postgres ORMto provide easy bindings between your dart classes and postgres database. It supports all kinds ofrelations without any complex configuration.


Quick Start

To get started, addstormberryas a dependency andbuild_runneras a dev dependency:

dart pub add stormberry
dart pub add build_runner --dev

In your code, specify an abstract class that should act as a table like this:

// This file is "model.dart"
import'package:stormberry/stormberry.dart';

// Will be generated by stormberry
part'model.schema.dart';

@Model()
abstractclassUser{
@PrimaryKey()
Stringgetid;

Stringgetname;
}

In order to generate the database code, run the following command:

dart run build_runner build

Tip:You'll need to re-run code generation each time you are making changes to your models. During development, you can usewatchto automatically watch your changes:dart pub run build_runner watch.

This will generate a.schema.dartfile that you should add as apartto the original model file.


Before running your application, you have to migrate your database. To do this run:

dart run stormberry migrate

This will ask you for the connection details of your postgres database and then migrate the database schema by adding theuserstable.


To access your database from your application, create aDatabaseinstance and use theusers repository like this:

voidmain()async{

vardb=Database(
// connection parameters go here
);

// adds a user to the 'users' table
awaitdb.users.insertOne(UserInsertRequest(id:'abc',name:'Alex'));

// finds a user by its 'id'
varuser=awaitdb.users.queryUser('abc');

assert(user.name=='Alex');
}

Full Documentation

See the full documentationhere or jump directly to the topic you are looking for: