Skip to content

Commit 4cba230

Browse files
committed
Fixes #53: TS WITHOUT TZ are returned as String, TS WITH TZ are converted to Instants properly JSON formatted
1 parent 18e90d4 commit 4cba230

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

src/main/asciidoc/groovy/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/java/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/js/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/ruby/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLConnectionImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
import io.vertx.ext.sql.TransactionIsolation;
3030
import io.vertx.ext.sql.UpdateResult;
3131
import org.joda.time.DateTime;
32+
import org.joda.time.DateTimeZone;
3233
import org.joda.time.LocalDate;
3334
import org.joda.time.LocalDateTime;
3435
import scala.Option;
3536
import scala.concurrent.ExecutionContext;
3637
import scala.runtime.AbstractFunction1;
3738

38-
import java.util.ArrayList;
39-
import java.util.Collections;
40-
import java.util.List;
41-
import java.util.UUID;
39+
import java.time.Instant;
40+
import java.util.*;
4241

4342
/**
4443
* Implementation of {@link SQLConnection} using the {@link AsyncConnectionPool}.
@@ -323,7 +322,7 @@ public Void apply(Object value) {
323322
} else if (value instanceof LocalDate) {
324323
array.add(value.toString());
325324
} else if (value instanceof DateTime) {
326-
array.add(value.toString());
325+
array.add(Instant.ofEpochMilli(((DateTime) value).getMillis()));
327326
} else if (value instanceof UUID) {
328327
array.add(value.toString());
329328
} else {

src/test/java/io/vertx/ext/asyncsql/PostgreSQLTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.vertx.ext.sql.ResultSet;
2222
import io.vertx.ext.unit.Async;
2323
import io.vertx.ext.unit.TestContext;
24+
import java.time.Instant;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

@@ -128,4 +129,29 @@ public void testUpdatingNumericField(TestContext context) {
128129
});
129130
}
130131

132+
@Test
133+
public void testInstant(TestContext context) {
134+
Async async = context.async();
135+
client.getConnection(ar -> {
136+
ensureSuccess(context, ar);
137+
conn = ar.result();
138+
conn.execute("DROP TABLE IF EXISTS test_table", ar1 -> {
139+
ensureSuccess(context, ar1);
140+
conn.execute("CREATE TABLE test_table (instant TIMESTAMP)", ar2 -> {
141+
ensureSuccess(context, ar2);
142+
Instant now = Instant.now();
143+
conn.queryWithParams("INSERT INTO test_table (instant) VALUES (?)", new JsonArray().add(now), ar3 -> {
144+
ensureSuccess(context, ar3);
145+
conn.query("SELECT instant FROM test_table", ar4 -> {
146+
ensureSuccess(context, ar4);
147+
// timestamps with out time zone are returned as strings, so we must compare to the original instant
148+
// ignoring the timezone offset (meaning ignore everything after char 23)
149+
context.assertEquals(ar4.result().getResults().get(0).getString(0), now.toString().substring(0, 23));
150+
async.complete();
151+
});
152+
});
153+
});
154+
});
155+
});
156+
}
131157
}

0 commit comments

Comments
 (0)