Skip to content

Commit

Permalink
fix: Update README & minor documentation touchups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordyn Newnham authored and Huskehhh committed Mar 5, 2024
1 parent ec7941c commit 60257ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 66 deletions.
80 changes: 26 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ A simple, clean and effective JDBC wrapper built on top of [HikariCP](https://gi
To integrate this library in your project using maven, add these to your pom.xml

```xml

<repository>
<id>husk</id>
<url>https://maven.husk.pro/repository/maven-releases/</url>
</repository>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

```xml

<dependency>
<groupId>pro.husk</groupId>
<artifactId>mysql</artifactId>
<version>1.4.2</version>
<groupId>com.github.Huskehhh</groupId>
<artifactId>MySQL</artifactId>
<version>CHANGEME</version>
</dependency>
```

Expand All @@ -33,24 +33,23 @@ Add this to repositories

```kotlin
maven {
url = uri("https://maven.husk.pro/repository/maven-releases/")
url = uri("https://jitpack.io")
}
```

And add this to dependencies

```kotlin
implementation("pro.husk:mysql:1.4.1")
implementation("com.github.Huskehhh:MySQL:CHANGEME")
```

#### Note: it is assumed that mysql-connector-java is provided
#### Note: it is assumed that mysql-connector-java is provided on the classpath.

If it is not, please also add

For Maven

```xml

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand All @@ -66,59 +65,32 @@ implementation("mysql:mysql-connector-java:VERSION")

Versions can be found [here](https://mvnrepository.com/artifact/mysql/mysql-connector-java)

#### What if I don't use a build tool

Alternatively, you can also just compile from
source, [download a compiled version](https://github.com/Huskehhh/MySQL/actions) and add it to your classpath, or supply
the files in your project workspace!

## Usage

### Create the database
### Instantiate the MySQL wrapper.

```Java
// Create instance
MySQL mysql=new MySQL(url,username,password);
```java
MySQL mysql = new MySQL(url, username, password);
```

### Query

For queries, there's two different ways we can do it!

If we are just processing data, we can do it this way (so we don't have to clean up resources later! (Recommended))
Sync & async functions are provided, depending on your use case.

#### Sync query
#### Example sync query

```Java
// Execute query
mysql.query("SELECT * from table WHERE id = 1;",results->{
if(results!=null){
// do something
}
});
```

...or you can get the ResultSet itself through

```Java
try(ResultSet results=mysql.query(query)){
// Do something with the ResultSet

// Then close statement (the ResultSet will close itself)
results.getStatement().close();
}catch(SQLException e){
e.printStackTrace();
}
```java
mysql.query("SELECT * from table WHERE id = 1;", results -> {
if (results != null) {
// Do something
}
});
```

Please make sure you close resources, or you'll end up with a memory leak! D:

### Update

#### Sync update

```Java
int resultCode=mysql.update("INSERT INTO `whitelist` (`uuid`, `date_added`) VALUES ('"+uuid+"', CURRENT_DATE());")
#### Example sync update

// Check result, do something
```java
int retval = mysql.update("INSERT INTO `whitelist` (`uuid`, `date_added`) VALUES ('"+uuid+"', CURRENT_DATE());")
```
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>pro.husk</groupId>
<artifactId>mysql</artifactId>
<version>1.4.2</version>
<packaging>jar</packaging>

<name>mysql</name>

<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<distributionManagement>
<repository>
<id>husk</id>
<url>https://maven.husk.pro/repository/maven-releases/</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -63,7 +52,6 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>mysql</groupId>
Expand Down

0 comments on commit 60257ca

Please sign in to comment.