Skip to content

Commit f016665

Browse files
author
Irenej Marc
committed
Initial commit, basic functionality
0 parents  commit f016665

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

Diff for: LICENSE.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Irenej Marc
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# dpq - A D PostgreSQL library
2+
3+
dpq wraps the libpq library and aims to provide a simple and modern way to access PostgreSQL in the D programming language.
4+
5+
Very incomplete for now.
6+
7+
## Current features:
8+
- Opening a connection using a connection string
9+
- Queries
10+
- Fetching the results of queries in binary format
11+
12+
## Planned features
13+
- Object-relational mapping
14+
- Automatic schema creating from objects
15+
- Connection pooling
16+
- a Query object of some kind to simplify querying
17+
- foreach looping through results
18+
- Errors messages and exceptions :)
19+
20+
## Documentation
21+
There is no docs yet, in the future, they should be written into the source code itself.
22+
23+
## Some notes:
24+
- If a wrong type is specified while fetching a column, the results are undefined. Most likely just garbage
25+
- Errors on connecting throw an exception, other errors don't (yet)
26+
- Fetching result data is only possible via indexes for now (using `Connection.get(int row, int col)`)
27+
28+
## Licence
29+
MIT, read LICENSE.txt
30+
31+
## Very simple example code
32+
33+
```d
34+
import std.stdio;
35+
36+
import dpq.connection;
37+
38+
import std.stdio;
39+
40+
void main()
41+
{
42+
writeln("Connecting");
43+
auto conn = SQLConnection("host=10.2.0.2 dbname=testdb user=testuser password='VerySecureTestPassword'");
44+
writefln("Error message from connection: \"%s\"", conn.errorMessage);
45+
writeln("Connected");
46+
writefln("Database name is: %s.", conn.db);
47+
writefln("Current user is: %s.", conn.user);
48+
49+
writeln("Sending a query");
50+
auto res = conn.execParams("SELECT $1::int, $2::text", 1, "asd");
51+
writeln("Sent a query");
52+
writefln("Error message from connection: \"%s\"", conn.errorMessage);
53+
54+
writefln("Query result rows: %d.", res.rows);
55+
writefln("Query result columns: %d.", res.columns);
56+
57+
writefln("result.get(0, 0) is: %d", res.get!int(0, 0));
58+
writefln("result.get(0, 2) is: %s", res.get!string(0, 1));
59+
}
60+
61+
```

Diff for: dub.sdl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name "dpq"
2+
description "A minimal D application."
3+
copyright "Copyright © 2016, Irenej"
4+
dependency "derelict-pq" version="1.0.1"
5+
authors "Irenej"

Diff for: dub.selections.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fileVersion": 1,
3+
"versions": {
4+
"derelict-pq": "1.0.1",
5+
"derelict-util": "2.0.4"
6+
}
7+
}

Diff for: source/app.d

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import std.stdio;
2+
3+
import dpq.connection;
4+
5+
import std.stdio;
6+
7+
void main()
8+
{
9+
writeln("Connecting");
10+
auto conn = SQLConnection("host=10.2.0.2 dbname=testdb user=testuser password='VerySecureTestPassword'");
11+
writefln("Error message from connection: \"%s\"", conn.errorMessage);
12+
writeln("Connected");
13+
writefln("Database name is: %s.", conn.db);
14+
writefln("Current user is: %s.", conn.user);
15+
16+
writeln("Sending a query");
17+
auto res = conn.execParams("SELECT $1::int, $2::text", 1, "asd");
18+
writeln("Sent a query");
19+
writefln("Error message from connection: \"%s\"", conn.errorMessage);
20+
21+
writefln("Query result rows: %d.", res.rows);
22+
writefln("Query result columns: %d.", res.columns);
23+
24+
writefln("result.get(0, 0) is: %d", res.get!int(0, 0));
25+
writefln("result.get(0, 2) is: %s", res.get!string(0, 1));
26+
27+
28+
}

0 commit comments

Comments
 (0)