ddbc.pods

DDBC - D DataBase Connector - abstraction layer for RDBMS access, with interface similar to JDBC.

Source file ddbc/drivers/pgsqlddbc.d. DDBC library attempts to provide implementation independent interface to different databases.

Set of supported RDBMSs can be extended by writing Drivers for particular DBs.

JDBC documentation can be found here: http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/package-summary.html

This module contains implementation POD utilities.

1 import ddbc;
2 import std.stdio;
3 
4 // prepare database connectivity
5 auto conn = createConnection("sqlite:ddbctest.sqlite");
6 scope(exit) conn.close();
7 Statement stmt = conn.createStatement();
8 scope(exit) stmt.close();
9 // fill database with test data
10 stmt.executeUpdate("DROP TABLE IF EXISTS user");
11 stmt.executeUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255) NOT NULL, flags int null)");
12 stmt.executeUpdate(`INSERT INTO user (id, name, flags) VALUES (1, "John", 5), (2, "Andrei", 2), (3, "Walter", 2), (4, "Rikki", 3), (5, "Iain", 0), (6, "Robert", 1)`);
13 
14 // our POD object
15 struct User {
16     long id;
17     string name;
18     int flags;
19 }
20 
21 writeln("reading all user table rows");
22 foreach(e; stmt.select!User) {
23     writeln("id:", e.id, " name:", e.name, " flags:", e.flags);
24 }
25 
26 writeln("reading user table rows with where and order by");
27 foreach(e; stmt.select!User.where("id < 6").orderBy("name desc")) {
28     writeln("id:", e.id, " name:", e.name, " flags:", e.flags);
29 }

Members

Functions

camelCaseToUnderscoreDelimited
string camelCaseToUnderscoreDelimited(immutable string s)

converts camel case MyEntityName to my_entity_name

generateDeleteSQL
string generateDeleteSQL()

returns "DELETE FROM <table name> WHERE id=id

generateInsertSQL
string generateInsertSQL()

returns "INSERT INTO <table name> (<field list>) VALUES (value list)

generateSelectForGetSQL
string generateSelectForGetSQL()

returns "SELECT <field list> FROM <table name>"

generateSelectSQL
string generateSelectSQL()

returns "SELECT <field list> FROM <table name>"

generateSelectSQL
string generateSelectSQL()

returns "SELECT <field list> FROM <table name>"

generateUpdateSQL
string generateUpdateSQL()

returns "UPDATE <table name> SET field1=value1 WHERE id=id

get
T get(ResultSet r)

Extract a row from the result set as the specified type. Requires that next has already been checked. Can be used for example to extract rows from executing a PreparedStatement.

getColumnNamesForType
string[] getColumnNamesForType()

returns array of field names

getTableNameForType
string getTableNameForType()

returns table name for struct type

Structs

String
struct String

Wrapper around string, to distinguish between Null and NotNull fields: string is NotNull, String is Null -- same interface as in Nullable

select
struct select(T, fieldList...)

range for select query

Meta

Authors

Vadim Lopatin