Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schultek/stormberry
Access your postgres database effortlessly from dart code.
https://github.com/schultek/stormberry
dart hacktoberfest orm postgres sql
Last synced: 9 days ago
JSON representation
Access your postgres database effortlessly from dart code.
- Host: GitHub
- URL: https://github.com/schultek/stormberry
- Owner: schultek
- License: mit
- Created: 2021-04-27T19:15:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-05T18:08:22.000Z (9 months ago)
- Last Synced: 2024-10-27T22:44:00.772Z (14 days ago)
- Topics: dart, hacktoberfest, orm, postgres, sql
- Language: Dart
- Homepage: https://pub.dev/packages/stormberry
- Size: 432 KB
- Stars: 68
- Watchers: 4
- Forks: 17
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Stormberry
A strongly-typed postgres ORM to provide easy bindings between your dart classes and postgres database.
It supports all kinds of relations without any complex configuration.---
# Quick Start
To get started, add `stormberry` as a dependency and `build_runner` as a dev dependency:
```shell
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:
```dart
// This file is "model.dart"
import 'package:stormberry/stormberry.dart';// Will be generated by stormberry
part 'model.schema.dart';@Model()
abstract class User {
@PrimaryKey()
String get id;String get name;
}
```In order to generate the database code, run the following command:
```shell script
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 use `watch` to automatically watch your changes: `dart pub run build_runner watch`.*This will generate a `.schema.dart` file that you should add as a `part` to the original model file.
---
Before running your application, you have to migrate your database. To do this run:
```shell
dart run stormberry migrate
```This will ask you for the connection details of your postgres database and then migrate
the database schema by adding the `users` table.---
To access your database from your application, create a `Database` instance and use the `users`
repository like this:```dart
void main() async {
var db = Database(
// connection parameters go here
);
// adds a user to the 'users' table
await db.users.insertOne(UserInsertRequest(id: 'abc', name: 'Alex'));
// finds a user by its 'id'
var user = await db.users.queryUser('abc');
assert(user.name == 'Alex');
}
```## Full Documentation
See the full documentation [here](https://pub.dev/documentation/stormberry/latest/topics/Introduction-topic.html)
or jump directly to the topic you are looking for:- [**Models**](https://pub.dev/documentation/stormberry/latest/topics/Models-topic.html)
- [**Views**](https://pub.dev/documentation/stormberry/latest/topics/Views-topic.html)
- [**Database**](https://pub.dev/documentation/stormberry/latest/topics/Database-topic.html)
- [**Repositories**](https://pub.dev/documentation/stormberry/latest/topics/Repositories-topic.html)
- [**Queries & Actions**](https://pub.dev/documentation/stormberry/latest/topics/Queries%20&%20Actions-topic.html)
- [**Migration**](https://pub.dev/documentation/stormberry/latest/topics/Migration-topic.html)