Skip to content

Commit

Permalink
Complete revamp to the library
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobeine committed Dec 9, 2023
1 parent 3e53c6e commit d18adbc
Show file tree
Hide file tree
Showing 29 changed files with 499 additions and 81 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

204 changes: 204 additions & 0 deletions .idea/intellij-javadocs-4.0.1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 90 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,95 @@ dependencies {

### Examples

For the examples, make sure to check the test source <a href="https://github.com/Cobeine/SQLava/tree/master/src/test/java/me/cobeine/sqllava/test">here</a>.
#### Connection Examples:
```java
public class Test {
/**
* Connection example
* for driver classes @see me.cobeine.sqlava.connection.HikariDataSourcePresets.class
*/
private MySQLConnection connection = new MySQLConnection(CredentialsRecord.builder()
.add(BasicMySQLCredentials.DATABASE, "test")
.add(BasicMySQLCredentials.HOST, "host")
.add(BasicMySQLCredentials.PASSWORD, "password")
.add(BasicMySQLCredentials.JDBC_URL, "url") //use JdbcUrlBuilder
.build());

void methods(){
connection.connect();
connection.getLogger();
connection.getPool();
connection.getCredentialsRecord();
connection.closeConnection();
connection.prepareStatement(); // with args;

JdbcUrlBuilder.newBuilder()
.host("host")
.port(3306)
.database("test")
.setAuto_reconnect(true)
.build();
}

}

```
#### Table Example
```java

public class ExampleTable extends Table {


public ExampleTable() {
super("example");
addColumns(
Column.of("id", ColumnType.INT).settings(ColumnSettings.AUTO_INCREMENT, ColumnSettings.UNIQUE),
Column.of("uuid", ColumnType.TEXT).settings(ColumnSettings.NOT_NULL, ColumnSettings.UNIQUE).defaultValue("none"),
Column.of("name", ColumnType.VARCHAR).size(64).settings(ColumnSettings.NOT_NULL, ColumnSettings.UNIQUE).defaultValue("none"),
Column.of("rank", ColumnType.VARCHAR).size(64).settings(ColumnSettings.NOT_NULL).defaultValue("DEFAULT")
);
setPrimaryKey("id");

}
}
```

#### Query examples
```java
public class Examples {
public void examples() {

connection.prepareStatement(
Query.select("test").where("id").and("uuid"))
.setParameter(1, 5)
.setParameter(2, UUID.randomUUID())
.executeQueryAsync(result ->
result.executeIfPresent(resultSet -> {

int id = resultSet.getInt("id"); //examples

}).orElse(exception -> {
if (exception != null)
exception.printStackTrace();
}).apply()
);

//or

Query selectQuery = Query.select("table").where("uuid").and("id");
PreparedQuery query = selectQuery.prepareStatement(connection);
query.setParameter(1, UUID.randomUUID()).setParameter(2, 1);
try (ResultSet set = query.executeQuery()) {
set.getInt("id");//etc
} catch (SQLException e) {
e.printStackTrace();
}
}

}

```


### Contributing

Expand All @@ -73,6 +161,7 @@ Before contributing to this project, please note the following:


#### <p align="center">Thanks for reading & reviewing my project!</p>
##### <p align="center"> Special thanks to <a href="https://github.com/AkramLZ">@AkramLZ</a> for inspiration!</p>



Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package my.cobeine.sqlava.connection;
package me.cobeine.sqlava.connection;

import my.cobeine.sqlava.connection.database.query.QueryHandler;

import java.sql.SQLException;
import me.cobeine.sqlava.connection.database.query.QueryHandler;

/**
* @author <a href="https://github.com/Cobeine">Cobeine</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package my.cobeine.sqlava.connection;
package me.cobeine.sqlava.connection;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package my.cobeine.sqlava.connection;
package me.cobeine.sqlava.connection;

/**
* The enum Connection result.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package my.cobeine.sqlava.connection.auth;
package me.cobeine.sqlava.connection.auth;

import my.cobeine.sqlava.connection.Connection;
import me.cobeine.sqlava.connection.Connection;

/**
* @Author <a href="https://github.com/Cobeine">Cobeine</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.cobeine.sqlava.connection.auth;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* @Author <a href="https://github.com/Cobeine">Cobeine</a>
*/
@AllArgsConstructor
@Getter
public enum BasicMySQLCredentials implements CredentialsKey {
HOST("serverName", String.class,true),
PORT("port", Integer.class,true),
DATABASE("databaseName", String.class,true),
USERNAME("user", String.class,true),
PASSWORD("password", String.class,true),
MAX_LIFETIME("maximumLifetime", Integer.class,true),
DATASOURCE_CLASS_NAME("dataSourceClassName", String.class,false),
POOL_SIZE("poolSize", Integer.class,false),
JDBC_URL("jdbcUrl",String.class,false);

private final String key;
private final Class<?> dataType;
private final boolean property;

@Override
public CredentialsKey[] array() {
return values();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package my.cobeine.sqlava.connection.auth;
package me.cobeine.sqlava.connection.auth;

/**
* @Author <a href="https://github.com/Cobeine">Cobeine</a>
Expand Down
Loading

0 comments on commit d18adbc

Please sign in to comment.