Skip to content

New transaction #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 105 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Vert.x module uses the https://github.com/mauricio/postgresql-async drivers

## Requirements

* Vert.x 2.1+ (with Scala language module v1.0)
* Vert.x 2.1+ (with Scala language module v1.0.1+)
* A working PostgreSQL or MySQL server
* For testing PostgreSQL: A 'testdb' database on a local PostgreSQL install and a user called 'vertx'
* For testing MySQL: A 'testdb' database on a local MySQL install and a user called 'root'
Expand Down Expand Up @@ -102,10 +102,111 @@ Creates a prepared statement and lets you fill the `?` with values.
{
"action" : "prepared",
"statement" : "SELECT * FROM some_test WHERE name=? AND money > ?",
"values" : ["John", 1000]
"values" : ["Mr. Test", 15]
}

### raw - Raw commands

Use this action to send arbitrary commands to the database. You should be able to submit any query or insertion with this command.

Here is an example for creating a table in PostgreSQL:

{
"action" : "raw",
"command" : "CREATE TABLE some_test (
id SERIAL,
name VARCHAR(255),
email VARCHAR(255),
is_male BOOLEAN,
age INT,
money FLOAT,
wedding_date DATE
);"
}

And if you want to drop it again, you can send the following:

{
"action" : "raw",
"command" : "DROP TABLE some_test;"
}

### Transactions

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.
Nested transactions are not possible until now!

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)).
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.

#### transaction begin

This command starts a transaction. You get an Ok message back to which you can then reply with more statements.

{
"action" : "begin"
}

#### transaction commit

To commit a transaction you have to send the `commit` command.

{
"action" : "commit"
}

#### transaction rollback

To rollback a transaction you have to send the `rollback` command.

{
"action" : "rollback"
}

#### Example for a transaction

Here is a small example on how a transaction works.

{
"action" : "begin"
}

This will start the transaction. You get this response:

### transaction
{
"status" : "ok"
}

You can then reply to this message with the commands `select`, `prepared`, `insert` and `raw`.
A possible reply could be this:

{
"action" : "raw",
"command" : "UPDATE some_test SET email = 'foo@bar.com' WHERE id = 1"
}

You get a reply back depending on the statement you sent. In this case the answer would be:

{
"status" : "ok",
"rows" : 1,
"message" : "UPDATE 1"
}

If you want to make more statements you just have to reply to this message again with the next statement.
When you have done all statements you can `commit` or `rollback` the transaction.

{
"action" : "commit"
}

If everything worked, the last answer will be:

{
"status" : "ok"
}

#### old transaction command (deprecated, use the new transaction mechanism with begin and commit)

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.

Expand All @@ -129,33 +230,7 @@ Takes several statements and wraps them into a single transaction for the server
}
]
}

### raw - Raw commands

Use this action to send arbitrary commands to the database. You should be able to do submit any query or insertion with this command.

Here is an example for creating a table in PostgreSQL:

{
"action" : "raw",
"command" : "CREATE TABLE some_test (
id SERIAL,
name VARCHAR(255),
email VARCHAR(255),
is_male BOOLEAN,
age INT,
money FLOAT,
wedding_date DATE
);"
}

And if you want to drop it again, you can send the following:

{
"action" : "raw",
"command" : "DROP TABLE some_test;"
}


## Planned actions

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`.
Expand Down
119 changes: 0 additions & 119 deletions build.gradle

This file was deleted.

38 changes: 0 additions & 38 deletions gradle.properties

This file was deleted.

68 changes: 0 additions & 68 deletions gradle/maven.gradle

This file was deleted.

5 changes: 0 additions & 5 deletions gradle/setup.gradle

This file was deleted.

Loading