#Avocadorm

Avocadorm is an object-relational mapper (ORM), used to link database tables to Dart objects. Its main focus is to be easy and quick to use. This is achieved by placing all database-related information in the Entity class.

##Required dependencies## In order to use the Avocadorm, add the dependency in the pubspec.yaml, along with your database handler of choice, for example:

dependencies:
  magnetfruit_avocadorm: ">=0.1.0 <0.2.0"
  magnetfruit_mysql_database_handler: ">=0.1.0 <0.2.0"

##Entity class Entity classes are built to give all the information needed to create queries for the database. This is an example of a company.dart file:

part of entities;

@Table('company')
class Company extends Entity {

  @Column.PrimaryKey('company_id')
  int companyId;

  @Column('name')
  String name;

  @Column('country_id')
  int countryId;
  
  @Column.ManyToOneForeignKey('countryId')
  Country country;

  @Column.OneToManyForeignKey('companyId', onUpdate: ReferentialAction.CASCADE)
  List<Employee> employees;

}

###Entity interface Required. The entity classes must extend from the Entity class.

###Table metadata Required. Annotate the entity class with a Table metadata. The Table metadata's argument is the name of the database table.

###Column metadata Annotate the entity properties with a Column metadata. Properties that do not have this will not be mapped to a database table column, and will be skipped. This means you can add constructors, properties, and methods to an entity class that have nothing to do with the database.

##Entity library You can import the entity classes one by one to your project, but the easiest way to gather entities together is to create an entity library. This is a file, for example named entities.dart, that will contain the entities that the Avocadorm will map. A very simple entity library could look like this:

library entities;

import 'package:magnetfruit_entity/entity.dart';

part 'company.dart';
part 'country.dart';
part 'employee.dart';
part 'employee_type.dart';

This gives you only one file to import to your project, and they can all be added to the Avocadorm in one line of code.

If you have many entities, it is suggested that they, with the entity library file, be placed in their own folder, for example /entities.

##Constructing the Avocadorm When the entity classes are finished, they can be given to the Avocadorm. Create the Avocadorm by correctly setting a database handler, then add the entities to it.

avocadorm = new Avocadorm(databaseHandler)
  ..addEntitiesInLibrary('entities');

##Usage With a valid Avocadorm working, basic CRUD operations, and a few others, can be made. See the respective documentation for more information. - Creating; - Counting; - Reading; - Updating; - Saving; - Deleting.

##Usage example

var newEmployee = new Employee()
  ..name = 'Zyrthofar'
  ..email = [email protected]'
  ..companyId = 42
  ..employeeTypeId = 3;

avocadorm.create(newEmployee).then((pkValue) {
  print('New employee's id is ${pkValue}.');
});

See the project in /example for more.

Build Status

Libraries

magnetfruit_avocadorm

Library with everything required to create and use the Avocadorm.