strata 0.1.0 copy "strata: ^0.1.0" to clipboard
strata: ^0.1.0 copied to clipboard

An Ecto-inspired data mapping and changeset validation library for Dart.

Strata #

An Ecto-inspired data mapping and changeset validation library for Dart.

strata provides a robust, type-safe, and extensible API for interacting with your database. It is inspired by the best patterns from Elixir's Ecto, focusing on explicit data validation through changesets and a composable query API.

Features #

  • Ecto-style Changesets: A powerful Changeset class for validating and casting untrusted data before it ever hits your database.
  • Repo & Adapter Pattern: The main StrataRepo class provides a single, clean API for all database operations. It delegates the database-specific work to a StrataAdapter, so your application logic remains decoupled.
  • Codegen for Queries: Define your data models using @StrataSchema annotations. A code generator creates type-safe Query and Changeset classes for you, eliminating "magic strings" and providing editor autocompletion.
  • Migration Support: A simple Migration class is built-in, which adapters can use to manage database schema versions.

The Adapter Model #

strata is a "bring-your-own-database" library. This core package (strata) contains no database-specific code.

It only defines the contracts (like StrataAdapter) and the core logic (like Changeset and StrataRepo).

To use strata with a real database, you must use a specific adapter package.

  • strata_sqlite (Coming Soon)
  • strata_postgres (Future)
  • ...or create your own!

This model keeps the core library lightweight and allows you to swap out your data layer without rewriting your application logic.

Getting Started #

  1. Add strata as a dependency and build_runner as a dev dependency to your pubspec.yaml.

    name: my_app
    description: A new Dart application.
    
    environment:
      sdk: ^3.0.0
    
    dependencies:
      strata: ^1.0.0 # Or the latest version
    
    dev_dependencies:
      build_runner: ^2.0.0
      strata_builder: ^1.0.0 # This would be the name of your generator package
      lints: ^3.0.0
      test: ^1.25.0
    

    (Note: The strata_builder package is hypothetical based on your schema_generator.dart. You would need to publish this generator as a separate package, or include it in strata's dev_dependencies if it's meant to be used alongside build_runner.)

  2. Create your build.yaml file to configure the code generator.

    targets:
      $default:
        builders:
          strata|schema:
            enabled: true
    

Usage #

Here is a short example of defining a schema and using the Repo with a Changeset.

1. Define Your Schema #

Create a file like lib/account.dart. The @StrataSchema annotation and Schema mixin "tag" this class for the code generator.

// lib/account.dart
import 'package:strata/strata.dart';

part 'account.strata.dart';

@StrataSchema(table: 'accounts')
class Account with Schema {
  final int id;
  final String username;

  Account({required this.id, required this.username});

  @override
  String toString() => 'Account(id: $id, username: $username)';
}
0
likes
140
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

An Ecto-inspired data mapping and changeset validation library for Dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, build, build_runner, code_builder, dart_style, source_gen

More

Packages that depend on strata