Connection

Represents the PostgreSQL connection and allows executing queries on it.

struct Connection {}

Constructors

this
this(string connString)

Connection constructor

Members

Functions

addOidsFor
void addOidsFor(string typeName)
Undocumented in source. Be warned that the author may not have intended to support it.
allResults
Result[] allResults()

Calls nextResult until the value returned is null, the returns them as an array.

begin
void begin()

Begins a transaction block.

close
void close()

Close the connection manually

commit
void commit()

Commits current transaction

count
long count(string filter, U vals)

Returns a count of the rows matching the filter in the specified relation. Filter can be empty or not given to select a count of all the rows in the relation.

ensureSchema
void ensureSchema(bool createType)

Generates and runs the DDL from the given structures

escapeIdentifier
string escapeIdentifier(string str)

Escapes an identifier (column, function, table name, ...) to be used in a query.

escapeLiteral
string escapeLiteral(string str)

Escapes a string, to be used in a query

exec
Result exec(string command)

Executes the given string directly

execParams
Result execParams(string command, T params)

Executes the given string with given params

execParams
Result execParams(string command, Value[] params, bool async)

ditto, but taking an array of params, instead of variadic template

execPrepared
Result execPrepared(string name, Value[] params)
Undocumented in source. Be warned that the author may not have intended to support it.
execPrepared
Result execPrepared(string name, T params)
Undocumented in source. Be warned that the author may not have intended to support it.
find
T[] find(string filter, U vals)

Returns an array of the specified type, filtered with the given filter and params

findL
T[] findL(string filter, int limit, U vals)

Returns an array of the specified type, filtered with the given filter and params with length limited by limit

findOne
Nullable!T findOne(U id)

Returns the requested structure or a Nullable null value if no rows are returned

findOne
Nullable!T findOne(string filter, U vals)

Returns the requested structure, searches by the specified filter with given params

findOneBy
Nullable!T findOneBy(string col, U val)

Returns the requested structure, searches by the given column name with the given value If not rows are returned, a Nullable null value is returned

insert
bool insert(T val, bool async)

Inserts the given structure to the DB

insert
int insert(T vals, bool async)

Inserts the given array of structures to the DB as one query

insertAsync
void insertAsync(T val)

ditto, async

insertR
Result insertR(T val, string ret)

Inserts the given structure, returning whatever columns are specified by the second param as a normal Result.

insertR
Result insertR(T vals, string ret)

Inserts the given array structures in a singl query, returning whatever columns are specified by the second param as a normal Result.

isBusy
bool isBusy()

Equivalent to calling PQisBusy from libpq. Only useful if you're doing async stuff manually.

lastResult
Result lastResult()

Calls nextResult until null is returned, then retuns only the last non-null result.

nextResult
Result nextResult()

Blocks until a result is read, then returns it

opIndex
PreparedStatement opIndex(string name)
Undocumented in source. Be warned that the author may not have intended to support it.
prepare
Result prepare(string name, string command, T paramTypes)
Undocumented in source. Be warned that the author may not have intended to support it.
prepared
PreparedStatement prepared(string name)
Undocumented in source. Be warned that the author may not have intended to support it.
releaseSavepoint
void releaseSavepoint(Savepoint s)

Destroys savepoint in the current transaction block.

remove
int remove(U id)

Deletes the record in the given table, by its PK

remove
int remove(string filter, U vals)

Deletes rows in the specified relation, filtered by the given filter string and values

removeAsync
bool removeAsync(U id)
Undocumented in source. Be warned that the author may not have intended to support it.
removeAsync
bool removeAsync(string filter, U vals)

ditto, async

rollback
void rollback(Savepoint s)

Rollback the current transaction to savepoint.

savepoint
Savepoint savepoint(string name)

Creates savepoint in the current transaction block.

send
bool send(string command)

ditto, async

sendParams
void sendParams(string command, T params)

ditty, but async

sendParams
void sendParams(string command, Value[] params)

ditto, async

sendPrepared
bool sendPrepared(string name, Value[] params)
Undocumented in source. Be warned that the author may not have intended to support it.
sendPrepared
bool sendPrepared(string name, T params)
Undocumented in source. Be warned that the author may not have intended to support it.
update
int update(string filter, string update, U vals)

Updates records filtered by the filter string, setting the values as specified in the update string. Both should be SQL-syntax

update
int update(U id, Value[string] updates, bool async)

Similar to above update, but instead of acceptign a filter and and update string, always filters by the PK and updates with absolute values from the updates AA.

update
int update(U id, T updates, bool async)

Similar to above, but accepts the whole structure as an update param. Filters by the PK, updates ALL the values in the filtered rows.

updateAsync
void updateAsync(string filter, string update, U vals)

ditto, async

updateAsync
void updateAsync(U id, Value[string] updates)
Undocumented in source. Be warned that the author may not have intended to support it.
updateAsync
void updateAsync(U id, T updates)
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

db
const(string) db [@property getter]

Returns the name of the database currently selected

errorMessage
string errorMessage [@property getter]

Returns the last error message

host
const(string) host [@property getter]

ditto, but host

password
const(string) password [@property getter]

ditto, but password

port
const(ushort) port [@property getter]

ditto, but port

status
const(ConnStatusType) status [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
user
const(string) user [@property getter]

Returns the name of the current user

Examples

auto conn = Connection("host=localhost dbname=testdb user=testuser");
//conn.exec ...

Meta