Connection.findOne

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

The filter is not further escaped, so programmer needs to make sure not to properly escape or enclose reserved keywords (like user -> "user") so PostgreSQL can understand them.

If not rows are returned, a Nullable null value is returned

  1. Nullable!T findOne(U id)
  2. Nullable!T findOne(string filter, U vals)
    struct Connection
    Nullable!T
    findOne
    (
    T
    U...
    )
    (
    string filter
    ,
    )

Examples

1 Connection conn; // An established connection
2 struct User
3 {
4 	@serial @PKey int id;
5 	string username;
6 	int posts;
7 };
8 
9 auto user = conn.findOne!User("username = $1 OR posts > $2", "foo", 42);
10 if (!user.isNull)
11 {
12 	... // do something
13 }

Meta