Skip to content

Commit

Permalink
initial mysql support
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed Oct 3, 2018
1 parent bb85fd5 commit 1f84bb0
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.github.jasync-sql</groupId>
<artifactId>jasync-mysql</artifactId>
<version>0.8.33</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/reactiverse/mysqlclient/MysqlIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.reactiverse.mysqlclient;

import com.github.jasync.sql.db.RowData;
import io.reactiverse.pgclient.PgIterator;
import io.reactiverse.pgclient.Row;

import java.util.Iterator;

public class MysqlIterator implements PgIterator {
private final Iterator<RowData> iterator;

public MysqlIterator(Iterator<RowData> iterator) {
this.iterator = iterator;
}

@Override
public boolean hasNext() {
return iterator.hasNext();
}

@Override
public Row next() {
return new MysqlRow(iterator.next());
}
}
39 changes: 39 additions & 0 deletions src/main/java/io/reactiverse/mysqlclient/MysqlQueryResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.reactiverse.mysqlclient;

import com.github.jasync.sql.db.QueryResult;
import io.reactiverse.pgclient.PgResult;

import java.util.List;

public class MysqlQueryResult implements PgResult<MysqlRowSet> {
private final QueryResult queryResult;

public MysqlQueryResult(QueryResult queryResult) {
this.queryResult = queryResult;
}

@Override
public int rowCount() {
return (int) queryResult.getRowsAffected();
}

@Override
public List<String> columnsNames() {
return queryResult.getRows().columnNames();
}

@Override
public int size() {
return queryResult.getRows().size();
}

@Override
public MysqlRowSet value() {
return new MysqlRowSet(queryResult.getRows());
}

@Override
public PgResult<MysqlRowSet> next() {
return null;
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/reactiverse/mysqlclient/MysqlRow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.reactiverse.mysqlclient;

import com.github.jasync.sql.db.RowData;
import io.reactiverse.pgclient.Row;

public class MysqlRow implements Row {
public MysqlRow(RowData row) {

}
}
47 changes: 47 additions & 0 deletions src/main/java/io/reactiverse/mysqlclient/MysqlRowSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.reactiverse.mysqlclient;

import com.github.jasync.sql.db.ResultSet;
import io.reactiverse.pgclient.PgIterator;
import io.reactiverse.pgclient.PgRowSet;

import java.util.List;

public class MysqlRowSet implements PgRowSet {


private final com.github.jasync.sql.db.ResultSet resultSet;

public MysqlRowSet(ResultSet resultSet) {
this.resultSet = resultSet;
}

@Override
public PgIterator iterator() {
return new MysqlIterator(resultSet.iterator());
}

@Override
public int rowCount() {
throw new UnsupportedOperationException();
}

@Override
public List<String> columnsNames() {
return resultSet.columnNames();
}

@Override
public int size() {
return resultSet.size();
}

@Override
public PgRowSet value() {
return this;
}

@Override
public PgRowSet next() {
return null;
}
}
32 changes: 32 additions & 0 deletions src/main/java/io/reactiverse/mysqlclient/MyssqlClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.reactiverse.mysqlclient;

import com.github.jasync.sql.db.Connection;
import io.reactiverse.pgclient.PgClient;
import io.reactiverse.pgclient.PgRowSet;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;

public class MyssqlClient implements PgClient {

private final Connection client;
private final Vertx vertx;

public MyssqlClient(Connection client, Vertx vertx) {
this.client = client;
this.vertx = vertx;
}

@Override
public PgClient query(String sql, Handler<AsyncResult<PgRowSet>> handler) {
client.sendQuery(sql).whenCompleteAsync((a, t) -> {
if (t == null) {
handler.handle(Future.succeededFuture(new MysqlQueryResult(a).value()));
} else {
handler.handle(Future.failedFuture(t));
}
},vertx.nettyEventLoopGroup());
return this;
}
}

0 comments on commit 1f84bb0

Please sign in to comment.