🛠️ Code cleanup & added many new features #1
294
README.md
294
README.md
@ -15,9 +15,12 @@
|
|||||||
<h3 align="center">MySQL Toolkit</h3>
|
<h3 align="center">MySQL Toolkit</h3>
|
||||||
|
|
||||||
## About The Project
|
## About The Project
|
||||||
This is a small project for quickly managing a MySQL database in Java. It makes everyday life with a database much easier.
|
|
||||||
|
This is a small project for quickly managing a MySQL database in Java. It makes everyday life with a database much
|
||||||
|
easier.
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
1. Add the jitpack repository to your `pom.xml`
|
1. Add the jitpack repository to your `pom.xml`
|
||||||
```xml
|
```xml
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -37,186 +40,197 @@ This is a small project for quickly managing a MySQL database in Java. It makes
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Usage Examples
|
### Usage Examples
|
||||||
|
|
||||||
1. Create a connection
|
1. Create a connection
|
||||||
- Example of a constructor without optional specifications
|
- Example of a constructor without optional specifications
|
||||||
```java
|
```java
|
||||||
MySQLConnection connection = new MySQLConnection(hostname, username, password, database).connect();
|
MySQLConnection connection = new MySQLConnection(hostname, username, password, database).connect();
|
||||||
```
|
```
|
||||||
- Example of a constructor with optional login parameters
|
- Example of a constructor with optional login parameters
|
||||||
```java
|
```java
|
||||||
MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LoginParam.AUTO_RECONNECT, LoginParam.NO_SSL).connect();
|
MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LoginParam.AUTO_RECONNECT, LoginParam.NO_SSL).connect();
|
||||||
```
|
```
|
||||||
#### Login Parameters
|
#### Login Parameters
|
||||||
- DEFAULT *(useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)*
|
- DEFAULT *(
|
||||||
- NO_SSL *(useSSL=false)*
|
useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)*
|
||||||
- USE_SSL *(useSSL=true)*
|
- NO_SSL *(useSSL=false)*
|
||||||
- AUTO_RECONNECT *(autoReconnect=true)*
|
- USE_SSL *(useSSL=true)*
|
||||||
- UTF8_ENCODING *(characterEncoding=UTF-8)*
|
- AUTO_RECONNECT *(autoReconnect=true)*
|
||||||
- USE_UNICODE *(useUnicode=yes)*
|
- UTF8_ENCODING *(characterEncoding=UTF-8)*
|
||||||
- USE_TIMEZONE *(useTimezone=true)*
|
- USE_UNICODE *(useUnicode=yes)*
|
||||||
- TIMEZONE_UTC *(serverTimezone=UTC)*
|
- USE_TIMEZONE *(useTimezone=true)*
|
||||||
|
- TIMEZONE_UTC *(serverTimezone=UTC)*
|
||||||
2. Perform a default SQL query
|
2. Perform a default SQL query
|
||||||
- Get a ResultSet
|
- Get a ResultSet
|
||||||
```java
|
```java
|
||||||
connection.getResultSet("SELECT * FROM example WHERE test = ?", "test1");
|
connection.getResultSet("SELECT * FROM example WHERE test = ?", "test1");
|
||||||
```
|
```
|
||||||
- Perform an update
|
- Perform an update
|
||||||
```java
|
```java
|
||||||
connection.update("UPDATE example SET test = ? WHERE abc = ?", "test1", "test2");
|
connection.update("UPDATE example SET test = ? WHERE abc = ?", "test1", "test2");
|
||||||
```
|
```
|
||||||
3. Get something from a table with managers
|
3. Get something from a table with managers
|
||||||
1. Getting a string from the table
|
1. Getting a string from the table
|
||||||
```java
|
```java
|
||||||
String value = connection.getResult("query", "parameters")
|
String value = connection.getResult("query", "parameters")
|
||||||
.getString("column");
|
.getString("column");
|
||||||
```
|
```
|
||||||
2. Getting a list from the table
|
2. Getting a list from the table
|
||||||
```java
|
```java
|
||||||
ArrayList<String> list = connection.getResult("query", "parameters")
|
ArrayList<String> list = connection.getResult("query", "parameters")
|
||||||
.getList("column");
|
.getList("column");
|
||||||
```
|
```
|
||||||
or
|
or
|
||||||
```java
|
```java
|
||||||
ArrayList<HashMap<String, Object>> list = connection.getResult("query", "parameters")
|
ArrayList<HashMap<String, Object>> list = connection.getResult("query", "parameters")
|
||||||
.getList();
|
.getList();
|
||||||
```
|
```
|
||||||
4. Choosing Results
|
4. Choosing Results
|
||||||
```java
|
```java
|
||||||
connection
|
connection
|
||||||
.selectFrom("table")
|
.selectFrom("table")
|
||||||
.where("column", "value")
|
|
||||||
.limit(10)
|
|
||||||
.getResult();
|
|
||||||
```
|
|
||||||
5. Choosing Results with custom parameters
|
|
||||||
```java
|
|
||||||
connection.select()
|
|
||||||
.from("table")
|
|
||||||
.where("column", "value")
|
.where("column", "value")
|
||||||
.add("LIMIT 2,5")
|
.limit(10)
|
||||||
.getResult();
|
.getResult();
|
||||||
```
|
```
|
||||||
|
5. Choosing Results with custom parameters
|
||||||
|
```java
|
||||||
|
connection.select()
|
||||||
|
.from("table")
|
||||||
|
.where("column", "value")
|
||||||
|
.add("LIMIT 2,5")
|
||||||
|
.getResult();
|
||||||
|
```
|
||||||
4. Perform an update using managers
|
4. Perform an update using managers
|
||||||
1. Update a Table
|
1. Update a Table
|
||||||
```java
|
```java
|
||||||
connection
|
connection
|
||||||
.updateTo("table")
|
.updateTo("table")
|
||||||
.where("column", "value")
|
.where("column", "value")
|
||||||
.set("column", "newValue")
|
.set("column", "newValue")
|
||||||
.execute();
|
.execute();
|
||||||
```
|
```
|
||||||
2. Generate a Table
|
2. Generate a Table
|
||||||
```java
|
```java
|
||||||
connection
|
connection
|
||||||
.generateTable("table")
|
.generateTable("table")
|
||||||
.addField(SQLType.STRING, "column", 999)
|
.addField(SQLType.STRING, "column", 999)
|
||||||
.addField(SQLType.STRING, "column2", 25)
|
.addField(SQLType.STRING, "column2", 25)
|
||||||
.create();
|
.create();
|
||||||
```
|
```
|
||||||
3. Delete something from a table
|
3. Delete something from a table
|
||||||
```java
|
```java
|
||||||
connection
|
connection
|
||||||
.deleteFrom("table")
|
.deleteFrom("table")
|
||||||
.where("column", "value")
|
.where("column", "value")
|
||||||
.execute();
|
.execute();
|
||||||
```
|
```
|
||||||
5. The use of the table factory
|
5. The use of the table factory
|
||||||
1. Create a new table class
|
1. Create a new table class
|
||||||
```java
|
```java
|
||||||
import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
|
import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
|
||||||
import de.gnmyt.SQLToolkit.storage.SQLTable;
|
import de.gnmyt.SQLToolkit.storage.SQLTable;
|
||||||
|
|
||||||
public class ExampleTable extends SQLTable {
|
public class ExampleTable extends SQLTable {
|
||||||
|
|
||||||
public ExampleTable(MySQLConnection connection) {
|
public ExampleTable(MySQLConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String tableName() {
|
protected String tableName() {
|
||||||
return "example";
|
return "example";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tableFields() {
|
protected void tableFields() {
|
||||||
string("column1", 255, "default");
|
string("column1", 255, "default");
|
||||||
string("colum2", 100, "test2");
|
string("colum2", 100, "test2");
|
||||||
integer("colum3", 2, "");
|
integer("colum3", 2, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSomething() {
|
public void addSomething() {
|
||||||
insert()
|
insert()
|
||||||
.value("column1", "test")
|
.value("column1", "test")
|
||||||
.value("colum3", 52)
|
.value("colum3", 52)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteUser() {
|
public void deleteUser() {
|
||||||
delete()
|
delete()
|
||||||
.where("column1", "test")
|
.where("column1", "test")
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
2. Register your table
|
2. Register your table
|
||||||
```java
|
```java
|
||||||
connection.getTableFactory().register(new ExampleTable(connection));
|
connection.getTableFactory().register(new ExampleTable(connection));
|
||||||
```
|
```
|
||||||
3. Now you can access your table from everywhere
|
3. Now you can access your table from everywhere
|
||||||
```java
|
```java
|
||||||
((ExampleTable) connection.getTableFactory().getTable(ExampleTable.class))
|
((ExampleTable) connection.getTableFactory().getTable(ExampleTable.class))
|
||||||
.addSomething();
|
.addSomething();
|
||||||
```
|
```
|
||||||
6. The use of the table factory with storage mediums
|
6. The use of the table factory with storage mediums
|
||||||
1. Create a new storage medium class
|
1. Create a new storage medium class
|
||||||
```java
|
```java
|
||||||
import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
|
import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
|
||||||
import de.gnmyt.SQLToolkit.storage.SQLStorageMedium;
|
import de.gnmyt.SQLToolkit.storage.SQLStorageMedium;
|
||||||
|
|
||||||
public class ExampleStorage extends SQLStorageMedium {
|
public class ExampleStorage extends SQLStorageMedium {
|
||||||
|
|
||||||
public ExampleStorage(MySQLConnection connection) {
|
public ExampleStorage(MySQLConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String tableName() {
|
protected String tableName() {
|
||||||
return "example_storage";
|
return "example_storage";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
2. Register your storage
|
2. Register your storage
|
||||||
```java
|
```java
|
||||||
connection.getTableFactory().register(new ExampleStorage(connection));
|
connection.getTableFactory().register(new ExampleStorage(connection));
|
||||||
```
|
```
|
||||||
3. Now you can access your storage medium from everywhere.
|
3. Now you can access your storage medium from everywhere. Try something like that:
|
||||||
Try something like that:
|
```java
|
||||||
```java
|
SQLStorageMedium storage = connection.getTableFactory().getStorage(ExampleStorage.class);
|
||||||
SQLStorageMedium storage = connection.getTableFactory().getStorage(ExampleStorage.class);
|
|
||||||
|
|
||||||
storage.insert("username", "test");
|
storage.insert("username", "test");
|
||||||
String username = storage.get("username");
|
String username = storage.get("username");
|
||||||
storage.delete("username");
|
storage.delete("username");
|
||||||
|
|
||||||
storage.insertOrUpdate("version", "1.0.0");
|
storage.insertOrUpdate("version", "1.0.0");
|
||||||
|
|
||||||
storage.getEntries();
|
storage.getEntries();
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Distributed under the MIT License. See `LICENSE` for more information.
|
Distributed under the MIT License. See `LICENSE` for more information.
|
||||||
|
|
||||||
## End
|
## End
|
||||||
Currently there are not many features yet, so feel free to write me some suggestions!
|
|
||||||
|
Currently, there are not many features yet, so feel free to write me some suggestions!
|
||||||
|
|
||||||
[contributors-shield]: https://img.shields.io/github/contributors/gnmyt/sqltoolkit.svg?style=for-the-badge
|
[contributors-shield]: https://img.shields.io/github/contributors/gnmyt/sqltoolkit.svg?style=for-the-badge
|
||||||
|
|
||||||
[contributors-url]: https://github.com/gnmyt/sqltoolkit/graphs/contributors
|
[contributors-url]: https://github.com/gnmyt/sqltoolkit/graphs/contributors
|
||||||
|
|
||||||
[forks-shield]: https://img.shields.io/github/forks/gnmyt/sqltoolkit.svg?style=for-the-badge
|
[forks-shield]: https://img.shields.io/github/forks/gnmyt/sqltoolkit.svg?style=for-the-badge
|
||||||
|
|
||||||
[forks-url]: https://github.com/gnmyt/sqltoolkit/network/members
|
[forks-url]: https://github.com/gnmyt/sqltoolkit/network/members
|
||||||
|
|
||||||
[stars-shield]: https://img.shields.io/github/stars/gnmyt/sqltoolkit.svg?style=for-the-badge
|
[stars-shield]: https://img.shields.io/github/stars/gnmyt/sqltoolkit.svg?style=for-the-badge
|
||||||
|
|
||||||
[stars-url]: https://github.com/gnmyt/sqltoolkit/stargazers
|
[stars-url]: https://github.com/gnmyt/sqltoolkit/stargazers
|
||||||
|
|
||||||
[issues-shield]: https://img.shields.io/github/issues/gnmyt/sqltoolkit.svg?style=for-the-badge
|
[issues-shield]: https://img.shields.io/github/issues/gnmyt/sqltoolkit.svg?style=for-the-badge
|
||||||
|
|
||||||
[issues-url]: https://github.com/gnmyt/sqltoolkit/issues
|
[issues-url]: https://github.com/gnmyt/sqltoolkit/issues
|
||||||
|
|
||||||
[license-shield]: https://img.shields.io/github/license/gnmyt/sqltoolkit.svg?style=for-the-badge
|
[license-shield]: https://img.shields.io/github/license/gnmyt/sqltoolkit.svg?style=for-the-badge
|
||||||
|
|
||||||
[license-url]: https://github.com/gnmyt/sqltoolkit/blob/master/LICENSE.txt
|
[license-url]: https://github.com/gnmyt/sqltoolkit/blob/master/LICENSE.txt
|
||||||
|
Reference in New Issue
Block a user