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
+105-30
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers
4
4
5
5
## Requirements
6
6
7
-
* Vert.x 2.1+ (with Scala language module v1.0)
7
+
* Vert.x 2.1+ (with Scala language module v1.0.1+)
8
8
* A working PostgreSQL or MySQL server
9
9
* For testing PostgreSQL: A 'testdb' database on a local PostgreSQL install and a user called 'vertx'
10
10
* For testing MySQL: A 'testdb' database on a local MySQL install and a user called 'root'
@@ -102,10 +102,111 @@ Creates a prepared statement and lets you fill the `?` with values.
102
102
{
103
103
"action" : "prepared",
104
104
"statement" : "SELECT * FROM some_test WHERE name=? AND money > ?",
105
-
"values" : ["John", 1000]
105
+
"values" : ["Mr. Test", 15]
106
106
}
107
+
108
+
### raw - Raw commands
109
+
110
+
Use this action to send arbitrary commands to the database. You should be able to submit any query or insertion with this command.
111
+
112
+
Here is an example for creating a table in PostgreSQL:
113
+
114
+
{
115
+
"action" : "raw",
116
+
"command" : "CREATE TABLE some_test (
117
+
id SERIAL,
118
+
name VARCHAR(255),
119
+
email VARCHAR(255),
120
+
is_male BOOLEAN,
121
+
age INT,
122
+
money FLOAT,
123
+
wedding_date DATE
124
+
);"
125
+
}
126
+
127
+
And if you want to drop it again, you can send the following:
128
+
129
+
{
130
+
"action" : "raw",
131
+
"command" : "DROP TABLE some_test;"
132
+
}
133
+
134
+
### Transactions
135
+
136
+
These commands let you begin a transaction and send an arbitrary number of statements within the started transaction. You can then commit or rollback the transaction.
137
+
Nested transactions are not possible until now!
138
+
139
+
Remember to reply to the messages after you send the `begin` command. Look in the docs how this works (e.g. for Java: [http://vertx.io/core_manual_java.html#replying-to-messages](http://vertx.io/core_manual_java.html#replying-to-messages)).
140
+
With replying to the messages, the module is able to send all statements within the same transaction. If you don't reply within the `timeoutTransaction` interval, the transaction will automatically fail and rollback.
141
+
142
+
#### transaction begin
143
+
144
+
This command starts a transaction. You get an Ok message back to which you can then reply with more statements.
145
+
146
+
{
147
+
"action" : "begin"
148
+
}
149
+
150
+
#### transaction commit
151
+
152
+
To commit a transaction you have to send the `commit` command.
153
+
154
+
{
155
+
"action" : "commit"
156
+
}
157
+
158
+
#### transaction rollback
159
+
160
+
To rollback a transaction you have to send the `rollback` command.
161
+
162
+
{
163
+
"action" : "rollback"
164
+
}
165
+
166
+
#### Example for a transaction
167
+
168
+
Here is a small example on how a transaction works.
169
+
170
+
{
171
+
"action" : "begin"
172
+
}
173
+
174
+
This will start the transaction. You get this response:
107
175
108
-
### transaction
176
+
{
177
+
"status" : "ok"
178
+
}
179
+
180
+
You can then reply to this message with the commands `select`, `prepared`, `insert` and `raw`.
181
+
A possible reply could be this:
182
+
183
+
{
184
+
"action" : "raw",
185
+
"command" : "UPDATE some_test SET email = 'foo@bar.com' WHERE id = 1"
186
+
}
187
+
188
+
You get a reply back depending on the statement you sent. In this case the answer would be:
189
+
190
+
{
191
+
"status" : "ok",
192
+
"rows" : 1,
193
+
"message" : "UPDATE 1"
194
+
}
195
+
196
+
If you want to make more statements you just have to reply to this message again with the next statement.
197
+
When you have done all statements you can `commit` or `rollback` the transaction.
198
+
199
+
{
200
+
"action" : "commit"
201
+
}
202
+
203
+
If everything worked, the last answer will be:
204
+
205
+
{
206
+
"status" : "ok"
207
+
}
208
+
209
+
#### old transaction command (deprecated, use the new transaction mechanism with begin and commit)
109
210
110
211
Takes several statements and wraps them into a single transaction for the server to process. Use `statement : [...actions...]` to create such a transaction. Only `select`, `insert` and `raw` commands are allowed right now.
111
212
@@ -129,33 +230,7 @@ Takes several statements and wraps them into a single transaction for the server
129
230
}
130
231
]
131
232
}
132
-
133
-
### raw - Raw commands
134
-
135
-
Use this action to send arbitrary commands to the database. You should be able to do submit any query or insertion with this command.
136
-
137
-
Here is an example for creating a table in PostgreSQL:
138
-
139
-
{
140
-
"action" : "raw",
141
-
"command" : "CREATE TABLE some_test (
142
-
id SERIAL,
143
-
name VARCHAR(255),
144
-
email VARCHAR(255),
145
-
is_male BOOLEAN,
146
-
age INT,
147
-
money FLOAT,
148
-
wedding_date DATE
149
-
);"
150
-
}
151
-
152
-
And if you want to drop it again, you can send the following:
153
-
154
-
{
155
-
"action" : "raw",
156
-
"command" : "DROP TABLE some_test;"
157
-
}
158
-
233
+
159
234
## Planned actions
160
235
161
236
You can always use `raw` to do anything on the database. If the statement is a query, it will return its results just like a `select`.
0 commit comments