Array of fields returned by the server
Class encapsulating prepared or non-prepared statements (commands).
Class representing connection to PostgreSQL server.
Class representing single query parameter
Collection of query parameters
Input range of DBRow!Specs
Class encapsulating errors and notices.
Exception thrown on server error
Contains information about fields returned by the server
Data type mapping:
PostgreSQL type | Aliases | Default D type | D type mapping possibilities |
---|---|---|---|
smallint | int2 | short | |
integer | int4 | int | |
bigint | int8 | long | |
oid | reg*** | uint | |
decimal | numeric | not yet supported | |
real | float4 | float | |
double precision | float8 | double | |
character varying(n) | varchar(n) | string | |
character(n) | char(n) | string | |
text | string | ||
"char" | char | ||
bytea | ubyte[] | ||
timestamp without time zone | timestamp | DateTime | |
timestamp with time zone | timestamptz | SysTime | |
date | Date | ||
time without time zone | time | TimeOfDay | |
time with time zone | timetz | SysTime | |
interval | Duration (without months and years) | ||
boolean | bool | bool | |
enums | string | enum | |
arrays | Variant[] | dynamic/static array with compatible element type | |
composites | record, row | Variant[] | dynamic/static array, struct or Tuple |
with vibe.d use -version=Have_vibe_d_core and use a ConnectionPool (PostgresDB Object & lockConnection)
1 2 auto pdb = new PostgresDB([ 3 "host" : "192.168.2.50", 4 "database" : "postgres", 5 "user" : "postgres", 6 "password" : "" 7 ]); 8 auto conn = pdb.lockConnection(); 9 10 auto cmd = new PGCommand(conn, "SELECT typname, typlen FROM pg_type"); 11 auto result = cmd.executeQuery; 12 13 try 14 { 15 foreach (row; result) 16 { 17 writeln(row["typname"], ", ", row[1]); 18 } 19 } 20 finally 21 { 22 result.close; 23 }
without vibe.d you can use std sockets with PGConnection object
1 import std.stdio; 2 import ddb.postgres; 3 4 int main(string[] argv) 5 { 6 auto conn = new PGConnection([ 7 "host" : "localhost", 8 "database" : "test", 9 "user" : "postgres", 10 "password" : "postgres" 11 ]); 12 13 scope(exit) conn.close; 14 15 auto cmd = new PGCommand(conn, "SELECT typname, typlen FROM pg_type"); 16 auto result = cmd.executeQuery; 17 18 try 19 { 20 foreach (row; result) 21 { 22 writeln(row[0], ", ", row[1]); 23 } 24 } 25 finally 26 { 27 result.close; 28 } 29 30 return 0; 31 }
Copyright Piotr Szturmaj 2011-.
PostgreSQL client implementation.
Features:
TODOs: