ddo 0.2.8

  • README.md
  • Installing
  • Versions
  • 43

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<DDOStatement>. DDOStatement is the main class to handle the results from the database. There are 3 main ways to retrieve information from a DDOStatement: fetch(), fetchAll(), and fetchColumn().

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 schema example needs to exist and the connection parameters need to be correct.

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

main() async {
	Driver driver = new DDOMySQL('127.0.0.1', 'example', 'root', 'password');
	DDO ddo = new DDO(driver);
	await ddo.exec('DROP TABLE IF EXISTS person');
	await ddo.exec('''
		CREATE TABLE IF NOT EXISTS `person` (
	`id` INT NOT NULL AUTO_INCREMENT,
		`name` VARCHAR(200) NOT NULL,
	`created` DATE NOT NULL,
	PRIMARY KEY (`id`));
	''');
	var now = new DateTime.now().toIso8601String();
	for(var x = 1; x <= 10; x++) {
		await ddo.exec("INSERT INTO person (`name`, `created`) VALUES ('person-${x}', '${now}')");
	}

	DDOStatement stmt = await ddo.query('select * from person');
	var results = stmt.fetchAll(DDO.FETCH_ASSOC);
	for(Map<String, dynamic> row in results) {
		for (String cName in row.keys) {
			print("Column '${cName}' has value '${row[cName]}'");
		}
	}
}

1. Depend on it

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


dependencies:
  ddo: "^0.2.8"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:ddo/ddo.dart';
        
Version Uploaded Documentation Archive
0.2.8 Mar 28, 2017 Go to the documentation of ddo 0.2.8 Download ddo 0.2.8 archive
0.2.7 Oct 21, 2015 Go to the documentation of ddo 0.2.7 Download ddo 0.2.7 archive
0.2.5 Aug 8, 2014 Go to the documentation of ddo 0.2.5 Download ddo 0.2.5 archive
0.2.4 Aug 1, 2014 Go to the documentation of ddo 0.2.4 Download ddo 0.2.4 archive
0.2.3 May 13, 2014 Go to the documentation of ddo 0.2.3 Download ddo 0.2.3 archive
0.2.2 May 6, 2014 Go to the documentation of ddo 0.2.2 Download ddo 0.2.2 archive
0.2.1 May 5, 2014 Go to the documentation of ddo 0.2.1 Download ddo 0.2.1 archive
0.2.0 May 1, 2014 Go to the documentation of ddo 0.2.0 Download ddo 0.2.0 archive
0.1.1 Apr 29, 2014 Go to the documentation of ddo 0.1.1 Download ddo 0.1.1 archive
0.1.0 Apr 12, 2014 Go to the documentation of ddo 0.1.0 Download ddo 0.1.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
93 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
76 / 100
Overall score:
Weighted score of the above. [more]
43

Platforms

Detected platforms: web, other

Primary library: package:ddo/ddo.dart with components: mirrors.

Suggestions

  • Fix lib/drivers/ddo_websql.dart.

    Strong-mode analysis of lib/drivers/ddo_websql.dart failed with the following error:

    line: 27 col: 21
    The element type 'int' can't be assigned to the map value type 'String'.

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • 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.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use ddo.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
postgresql >=0.2.14 <0.3.0 0.2.14 0.3.4+1
sqljocky ^0.14.1 0.14.1
Transitive dependencies
charcode 1.1.1
convert 1.1.1 2.0.1
crypto 0.9.2+1 2.0.2+1
logging 0.11.3+1
options_file 0.11.0
typed_data 1.1.5
Dev dependencies
browser any
test ^0.12.10