You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-19Lines changed: 32 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -10,26 +10,40 @@ Postgres-async-driver is available on [Maven Central](http://search.maven.org/#s
10
10
<dependency>
11
11
<groupId>com.github.alaisi.pgasync</groupId>
12
12
<artifactId>postgres-async-driver</artifactId>
13
-
<version>0.6</version>
13
+
<version>0.7</version>
14
14
</dependency>
15
15
```
16
16
17
17
## Usage
18
18
19
19
### Hello world
20
20
21
-
Queries are submitted to a `Db` with success and failure callbacks.
21
+
Querying for a set returns an [rx.Observable](http://reactivex.io/documentation/observable.html) that emits a single [ResultSet](https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/ResultSet.java).
22
22
23
23
```java
24
24
Db db =...;
25
-
db.query("select 'Hello world!' as message",
26
-
result -> out.println(result.row(0).getString("message") ),
Querying for rows returns an [rx.Observable](http://reactivex.io/documentation/observable.html) that emits 0-n [Rows](https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/Row.java).
33
+
34
+
```java
35
+
Db db =...;
36
+
db.queryRows("select unnest('{ hello, world }'::text[] as message)")
37
+
.map(row -> row.getString("message"))
38
+
.subscribe(System.out::println)
39
+
40
+
// => hello
41
+
// => world
28
42
```
29
43
30
44
### Creating a Db
31
45
32
-
Db is usually a connection pool that is created with [`com.github.pgasync.ConnectionPoolBuilder`](https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/ConnectionPoolBuilder.java)
46
+
Db is a connection pool that is created with [`com.github.pgasync.ConnectionPoolBuilder`](https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/ConnectionPoolBuilder.java)
33
47
34
48
```java
35
49
Db db =newConnectionPoolBuilder()
@@ -49,25 +63,24 @@ Each connection *pool* will start only one IO thread used in communicating with
49
63
Prepared statements use native PostgreSQL syntax `$index`. Supported parameter types are all primitive types, `String`, `BigDecimal`, `BigInteger`, `UUID`, temporal types in `java.sql` package and `byte[]`.
50
64
51
65
```java
52
-
db.query("insert into message(id, body) values($1, $2)", Arrays.asList(123, "hello"),
53
-
result -> out.printf("Inserted %d rows", result.updatedRows() ),
54
-
error -> error.printStackTrace() );
66
+
db.querySet("insert into message(id, body) values($1, $2)", 123, "hello"))
A transactional unit of work is started with `begin()`. Queries issued to transaction passed to callback are executed in the same transaction and the tx is automatically rolled back on query failure.
72
+
A transactional unit of work is started with `begin()`. Queries issued to the emitted [Transaction](https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/Transaction.java) are executed in the same transaction and the tx is automatically rolled back on query failure.
0 commit comments