-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Lightweight native D client for PostgreSQL database | ||
|
||
`postgres-native` is a native D implementation of the Postgres frontend/backend | ||
protocol. It is built in a way to pay attention to a memory allocations (memory | ||
will be reused, and only growing if the backend sends results that was larger | ||
than any of the results ever encountered). This way GC access can be completely | ||
avoided after some initial time. | ||
|
||
## Usage examples | ||
|
||
```D | ||
import postgres.connection; | ||
import postgres.row; | ||
import std.stdio; | ||
import std.algorighm; | ||
auto conn = Connection("127.0.0.1", 5432, "burgos", "pass", | ||
"dbname"); | ||
conn.connect(); | ||
struct ComicBook | ||
{ | ||
int id; | ||
@as("comic_hero") | ||
string hero; | ||
string title; | ||
} | ||
// Using callback for every row | ||
conn.query("SELECT id, comic_hero, title FROM commics WHERE id > 1", | ||
(PostgresRow row) | ||
{ | ||
import std.stdio; | ||
writeln(row.toStruct!Result); | ||
}); | ||
// Using range interface | ||
conn.queryRange("SELECT * FROM comic WHERE id >= 1") | ||
.map!(toStruct!Result) | ||
.filter!(x => x.hero == "Tex Willer").each!(writeln); | ||
``` |