Skip to content

Commit 6eff466

Browse files
committed
documentation for insert, select and raw commands
1 parent db1ca19 commit 6eff466

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers
44

55
## Requirements
66

7-
* Vert.x 2.0.0
7+
* Vert.x 2.0+
88

99
## Installation
1010

@@ -13,6 +13,7 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers
1313
## Configuration
1414

1515
{
16+
"address" : <event-bus-addres-to-listen-on>,
1617
"connection" : <MySQL|PostgreSQL>,
1718
"host" : <your-host>,
1819
"port" : <your-port>,
@@ -28,3 +29,87 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers
2829
* `username` - The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
2930
* `password` - The password to connect to the database. Default is not set, i.e. it uses no password.
3031
* `database` - The name of the database you want to connect to. Defaults to `test`.
32+
33+
34+
## Usage
35+
36+
All commands are relatively similar. Use JSON with the `action` field and add the needed parameters for each command.
37+
38+
There are only a few commands available currently, but in theory you should be able to invoke any command on the database with the `raw` action.
39+
40+
### Reply messages
41+
42+
The module will reply to all requests. In the message, there will be either a `"status" : "ok"` or a `"status" : "error"`. If the request could be processed without problems, it will result in an "ok" status. See an example here:
43+
44+
{
45+
"status" : "ok",
46+
"rows" : 2,
47+
"message" : "SELECT 2",
48+
"fields" : [ "name", "email", "is_male", "age", "money", "wedding_date" ],
49+
"results" : [
50+
["Mr. Test", "mr-test@example.com", true, 32, 123.45, "2014-04-04"],
51+
["Mrs. Test", "mrs-test@example.com", false, 16, 543.21, "2022-02-22"]
52+
]
53+
}
54+
55+
* `rows` gives you the number of rows affected by the statement sent to the server.
56+
* `message` is a status message from the server.
57+
* `fields` contains the list of fields of the selected table - Only present if the request resulted in a result set.
58+
* `results` contains a list of rows - Only present if the request resulted in a result set.
59+
60+
If the request resulted in an error, a possible reply message looks like this:
61+
62+
{
63+
"status" : "error",
64+
"message" : "message":"column \"ager\" does not exist"
65+
}
66+
67+
### insert
68+
69+
Use this action to insert new rows into a table. You need to specify a table, the fields to insert and an array of rows to insert. The rows itself are an array of values.
70+
71+
{
72+
"action" : "insert",
73+
"table" : "some_test",
74+
"fields" : ["name", "email", "is_male", "age", "money", "wedding_date"],
75+
"values" : [
76+
["Mr. Test", "mr-test@example.com", true, 32, 123.45, "2014-04-04"],
77+
["Mrs. Test", "mrs-test@example.com", false, 16, 543.21, "2022-02-22"]
78+
]
79+
}
80+
81+
### select
82+
83+
The `select` action creates a `SELECT` statement to get a projection from a table. You can filter the columns by providing a `fields` array. If you omit the `fields` array, it selects every column available in the table.
84+
85+
{
86+
"action" : "select",
87+
"table" : "some_test",
88+
"fields" : ["name", "email", "is_male", "age", "money", "wedding_date"]
89+
}
90+
91+
### raw - Raw commands
92+
93+
Use this action to send arbitrary commands to the database. You should be able to do submit any query or insertion with this command.
94+
95+
Here is an example for creating a table in PostgreSQL:
96+
97+
{
98+
"action" : "raw",
99+
"command" : "CREATE TABLE some_test (
100+
id SERIAL,
101+
name VARCHAR(255),
102+
email VARCHAR(255),
103+
is_male BOOLEAN,
104+
age INT,
105+
money FLOAT,
106+
wedding_date DATE
107+
);"
108+
}
109+
110+
And if you want to drop it again, you can send the following:
111+
112+
{
113+
"action" : "raw",
114+
"command" : "DROP TABLE some_test;"
115+
}

0 commit comments

Comments
 (0)