dabl 0.1.3 copy "dabl: ^0.1.3" to clipboard
dabl: ^0.1.3 copied to clipboard

Dart 1 only

A port of the Dabl ORM to Dart.

dabl-dart #

Dart programming language port of DABL.

About #

DABL is a database ORM that builds uses classes to represent and interact with each table in your database. Using these classes, table rows can be created, retrieved, updated, deleted, and counted using very simple and short commands without writing raw SQL (unless you want to). DABL is designed to make the repetitive tasks of database access easier using objects. DABL also recognizes foreign key relationships and automatically creates class methods for them.

Installing #

Add a reference to "dabl" in the project's "pubspec.yaml" and run "pub install".

Generating Models #

Use the DABL Generator project to create the models. Copy the generated files to your project directory. Use the generated "pubspec.yaml" as a basis for your project.

Using the models #

For this document, let's assume we have two tables. One table is "User" with the fields "ID", "Name", "Password", "Email", and "LastLogin" and the other table is "Car" with the fields "ID", "UserID" which is a foreign key to User.ID, "Make" and "Model".

Database access and Futures #

Any operation that has to talk to the database will return a Future. Make sure that your code can handle async operations.

Creation #

To create a new record, just create a new object, set the desired fields and then call "save":

User user = new User();
user.setName('Joe');
user.setPassword('sup3ers3cr3t');
user.email('joe@example.com');
user.save();

Retrieval #

There are static methods on the models that allow for retrieval of objects. Any foreign keys are automatically turned into retrieval methods. Remember that database access is async.

User.retrieveByName('Joe').then((User u) {
  u.getCars().then((List<Car> cars) {
    print(cars.first.getModel());
  });
});

Updating #

After retrieving (or creating), the model can be updated by changing the fields and then calling save.

User.retrieveByName('Joe').then((User u) {
  u.setEmail('joe.bob@example.com');
  u.save();
});

Deletion #

Deleting a record is easy.

User.retrieveByName('Joe').then((User u) {
  u.delete();
});

Counting #

Counting is slightly tricky. Any models related by foreign keys will have a "count" method.

User.retrieveByName('Joe').then((User u) {
  u.countCars().then((int count) {
    print("${u.getName()} has ${count} cars");
  });
});
0
likes
15
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

A port of the Dabl ORM to Dart.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dabl_query, ddo, intl

More

Packages that depend on dabl