ddo 0.2.4 copy "ddo: ^0.2.4" to clipboard
ddo: ^0.2.4 copied to clipboard

outdatedDart 1 only

A port of PHP Data Objects to Dart.

Dart Data Objects #

A port of PHP Data Objects to Dart.

DDO is an abstraction framework for accessing databases from Dart.

Note that this library is only to abstract the way the user interacts with a database, it doesn't rewrite SQL or implement missing features.

By extending the base driver, any database connection can be used. Two have been included, one for MySQL and WebSQL.

##Installation

In your pubspec.yaml file, add a dependency on "ddo". Since breaking changes are likely to happen (given the immaturity of this project), you should depend on a specific version like so:

dependencies:
  ddo: ">=0.2.2 <0.3.0"

Import the main library:

import 'package:ddo/ddo.dart';

Also make sure to import your desired driver

import 'package:ddo/drivers/ddo_mysql.dart';

The MySQL driver depends on SQLJocky so include that in your pubspec.yaml if you are connecting to a MySQL database.

##Usage Create a new Driver object:

Driver driver = new DDOMySQL('127.0.0.1', 'example', 'root', '');

Create a new DDO object by injecting your Driver:

DDO ddo = new DDO(driver);

Query the database using the DDO object:

ddo.query('select * from user');

Any direct database access is accomplished using Futures. Make sure you understand them and are comfortable using them.

The query method returns a Future

Fetch will return a single row at a time while fetchAll will return all rows as a List. FetchColumn will return a List of values of the sent column (for now, it only returns the first row's values, this part is incomplete).

What is returned by fetch and fetchAll depends on the fetch mode. The fetch mode can either be set on the statement itself or it can be set for each call to fetch and fetchAll.

FETCH_ASSOC will return a Map with the Keys being the column names and the values being the column values. FETCH_CLASS will use Mirrors to dynamically create an Object of the set class and return that. It works based on matching properties to column names.

Except for FETCH_CLASS, the returned value will be a DDOResult object (for fetch) or a DDOResults object (for fetchAll). A DDOResults object has many DDOResult results. A DDOResult has a row object containing the values retrieved from the database. This may be an unnecessary abstraction, so I'll revisit this in the future

##Full Example This example will query the user table and print out, for every row, every column and its values. Note that the database needs to exist, the connection parameters need to be correct and there needs to be a 'user' table.

import 'package:ddo/ddo.dart';
import 'package:ddo/drivers/ddo_mysql.dart';

main() {
  Driver driver = new DDOMySQL('127.0.0.1', 'example', 'root', '');
  DDO ddo = new DDO(driver);
  ddo.query('select * from user').then((DDOStatement stmt){
  DDOResults results = (stmt.fetchAll(DDO.FETCH_ASSOC) as DDOResults);
    for(DDOResult row in results.results) {
    	for(String cName in row.row.keys) {
    		print("Column '${cName}' has value '${row.row[cName]}'");
    	}
    }
  });
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A port of PHP Data Objects to Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

sqljocky, unittest

More

Packages that depend on ddo