jaguar_orm 0.2.4

  • Installing
  • Versions
  • 50


Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc


  • Relationships
  • Preloads
  • Cascading
    • Cascaded inserts
    • Cascaded updates
    • Cascaded removals
  • Migration
  • Polymorphic relations
  • Composite primary keys
  • Composite foreign keys

Gettings started

Install source generator

jaguar_orm_cli provides orm CLI tool to generate ORM code.

pub global activate jaguar_orm_cli

Project configuration

orm CLI tool reads project configuration from orm.yaml configuration file. The orm property in configuration file must list the paths of all libraries that need ORM generation.

Example orm.yaml file

  - bin/main.dart
  - lib/models/user.dart
  - lib/models/book.dart

Simple example


class User {
  String id;

  String name;

  static const String tableName = '_user';

  String toString() => "User($id, $name)";


A Bean performs database actions on behalf of the model. In this case, UserBean performs actions for User model. Much of the Bean's functionality will be source generated.

class UserBean extends Bean<User> with _UserBean {
  UserBean(Adapter adapter) : super(adapter);

Generating the Bean

Given the configuration and GenBean annotation, orm CLI can magically generate ORM methods for you. Here is the command:

orm build

We will see, how we can use the generated ORM methods to perform basic CRUD operations on User table/model.

Connecting to database

We will use PostgreSQL for this tutorial. PgAdapter is found in the package jaguar_query_postgresql.

PgAdapter _adapter =
    new PgAdapter('postgres://postgres:dart_jaguar@localhost/example');
await _adapter.connect();

Creating instance of bean

Beans internally use jaguar_query's Adapter interface to talk to database. Lets create an instance of UserBean.

final userBean = new UserBean(_adapter);

Dropping table

await userBean.drop();

Creating table

await userBean.createTable();

Inserting new record

await userBean.insert(new User() = '1' = 'teja');

Fetching record by primary key

User user = await userBean.find('1');

Fetching all records

List<User> users = await userBean.getAll();

Updating a record

User user = await userBean.find('1'); = 'teja hackborn';
await userBean.update(user);

Remove by id

await userBean.remove('1');

Remove all

await userBean.removeAll();

One-To-One example

class User {
  String id;

  String name;

  Address address;

  static const String tableName = '_user';

  String toString() => "User($id, $name, $address)";

class Address {
  String id;

  String userId;

  String street;

  static String tableName = 'address';

  String toString() => "Post($id, $userId, $street)";

class UserBean extends Bean<User> with _UserBean {
  UserBean(Adapter adapter)
      : addressBean = new AddressBean(adapter),

  final AddressBean addressBean;

  Future createTable() {
    final st = Sql
        .addStr('id', primary: true, length: 50)
        .addStr('name', length: 50);
    return execCreateTable(st);

class AddressBean extends Bean<Address> with _AddressBean {
  AddressBean(Adapter adapter) : super(adapter);

  Future createTable() {
    final st = Sql
        .addStr('id', primary: true, length: 50)
        .addStr('street', length: 150)
        .addStr('user_id', length: 50, foreignTable: '_user', foreignCol: 'id');
    return execCreateTable(st);

/// The adapter
PgAdapter _adapter =
    new PgAdapter('postgres://postgres:dart_jaguar@localhost/example');

main() async {
  // Connect to database
  await _adapter.connect();

  // Create beans
  final userBean = new UserBean(_adapter);
  final addressBean = new AddressBean(_adapter);

  // Drop old tables
  await addressBean.drop();
  await userBean.drop();

  // Create new tables
  await userBean.createTable();
  await addressBean.createTable();

  // Cascaded One-To-One insert
    final user = new User() = '1' = 'Teja'
      ..address = (new Address() = '1'
        ..street = 'Stockholm');
    await userBean.insert(user, cascade: true);

  // Fetch One-To-One preloaded
    final user = await userBean.find('1', preload: true);

  // Manual One-To-One insert
    User user = new User() = '2' = 'Kleak';
    await userBean.insert(user, cascade: true);

    user = await userBean.find('2');

    final address = new Address() = '2'
      ..street = 'Stockholm';
    addressBean.associateUser(address, user);
    await addressBean.insert(address);

  // Manual One-To-One preload
    final user = await userBean.find('2');
    user.address = await addressBean.findByUser(;

  // Preload many
    final users = await userBean.getAll();
    await userBean.preloadAll(users);

  // Cascaded One-To-One update
    User user = await userBean.find('1', preload: true); = 'Teja Hackborn';
    user.address.street = 'Stockholm, Sweden';
    await userBean.update(user, cascade: true);

  // Fetch One-To-One relationship preloaded
    final user = await userBean.find('1', preload: true);

  // Cascaded removal of One-To-One relation
  await userBean.remove('1', true);

  // Remove addresses belonging to a User
  await addressBean.removeByUser('2');




  • Create table


  • Angular like table specification


  • Removed statement generation
  • Moved generator to its own package
  • Relations


  • Initial version, created by Stagehand

1. Depend on it

Add this to your package's pubspec.yaml file:

  jaguar_orm: "^0.2.4"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:jaguar_orm/jaguar_orm.dart';
Version Uploaded Documentation Archive
0.2.4 Sep 24, 2017 Go to the documentation of jaguar_orm 0.2.4 Download jaguar_orm 0.2.4 archive
0.2.3 Sep 24, 2017 Go to the documentation of jaguar_orm 0.2.3 Download jaguar_orm 0.2.3 archive
0.1.3 Jun 10, 2017 Go to the documentation of jaguar_orm 0.1.3 Download jaguar_orm 0.1.3 archive
0.1.2 Jun 4, 2017 failed Download jaguar_orm 0.1.2 archive
0.1.1 Jun 4, 2017 failed Download jaguar_orm 0.1.1 archive
0.1.0 Jun 4, 2017 failed Download jaguar_orm 0.1.0 archive
0.0.4 Mar 5, 2017 failed Download jaguar_orm 0.0.4 archive
0.0.3 Feb 23, 2017 failed Download jaguar_orm 0.0.3 archive
0.0.1 Dec 25, 2016 failed Download jaguar_orm 0.0.1 archive
0.2.2-dev Sep 24, 2017 Go to the documentation of jaguar_orm 0.2.2-dev Download jaguar_orm 0.2.2-dev archive

All 12 versions...


We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jaguar_orm/jaguar_orm.dart.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use jaguar_orm.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
jaguar_query ^0.2.8 0.2.8
quiver ^0.25.0 0.25.0 0.29.0+1
Transitive dependencies
matcher 0.12.2
meta 1.1.2
path 1.5.1
stack_trace 1.9.2
Dev dependencies
jaguar_query_postgresql ^0.2.5
test >=0.12.0 <0.13.0