Skip to content

Generating ORM for simple table

Ravi Teja Gudapati edited this page Sep 25, 2018 · 7 revisions

Lets generate Bean for this simple model:

class User {
  @PrimaryKey(auto: true, isNullable: false)
  int id;

  String name;

  int age;

  User({this.id, this.name, this.age});
}

As you have noticed, the field id is declared as non-nullable, auto-incremented primary key using Column spec. For information about more Column specification annotations, look at the following wiki page.

Now, let us request Jaguar to generate the bean for us:

/// Bean logic is generated by Jaguar ORM
@GenBean()
class UserBean extends Bean<User> with _UserBean {
  UserBean(Adapter adapter) : super(adapter);

  String get tableName => 'simple_user';
}

The GenBean annotation triggers the generation of bean login in class _UserBean. Make sure you specify the table name using tableName field.

TODO

Clone this wiki locally