6 Commits
1.3.8 ... 1.3.9

Author SHA1 Message Date
cf61d7589b Update README.md 2022-12-08 22:09:39 +02:00
4d4af1622e Update README.md 2022-12-08 22:01:07 +02:00
af25e695f0 Update README.md 2022-12-08 22:00:30 +02:00
54e260e56b Small config fix & shade PostgreSQL driver 2022-12-08 21:54:08 +02:00
587f303ba5 Add max-connection-lifetime to config 2022-12-08 21:40:28 +02:00
8586aeefcd Re-add thread-pool-size config option, fixes #19 2022-12-08 21:33:09 +02:00
6 changed files with 29 additions and 10 deletions

View File

@@ -5,12 +5,13 @@
### Difference from original skript-db
- Fixed local variables disappearance in newer Skript versions (very hacky fix, but it works, so that's good!)
- Thread-pool size is now automatically increasing on demand with use of CachedThreadPool, instead of a fixed hard-coded number
- Uses newer versions of dependencies (Increased performance and security)
- Replaced `synchronously execute` with `quickly execute`, which allows to speed up queries by 50ms with some risk
- SQL Driver is configurable
- If a sql query is detected to be running on non-main thread, it becomes synchronous automatically
- SQL Driver is configurable, comes with shaded MariaDB and PostgreSQL drivers
- A few variable type related bugs fixed
- Uses Java 11 instead of Java 8
- Configurable max-connection-lifetime
### Installation
1. Use 1.8+ Minecraft server version.
@@ -21,7 +22,8 @@
Stores the connection information for a data source. This should be saved to a variable in a
`script load` event or manually through an effect command.
The url format for your database may vary! The example provided uses a MySQL database.
The url format for your database may vary depending on database you are using.
MariaDB/PostgreSQL users: make sure to check `config.yml` to use the correct driver.
#### Syntax
```
[the] data(base|[ ]source) [(of|at)] %string%
@@ -30,6 +32,9 @@ Stores the connection information for a data source. This should be saved to a v
#### Examples
```
set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
set {sql} to the database "mariadb://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
set {sql} to the database "postgresql://localhost:3306/mydatabase?user=admin&password=12345&ssl=false"
set {sql} to the database "sqlite:database.db"
```
---

View File

@@ -6,7 +6,7 @@
<groupId>com.btk5h</groupId>
<artifactId>skript-db</artifactId>
<version>1.3.8</version>
<version>1.3.9</version>
<packaging>jar</packaging>
<repositories>
@@ -103,6 +103,13 @@
<version>3.0.9</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -73,8 +73,14 @@ public final class SkriptDB extends JavaPlugin {
}
try {
if (out == null) return;
out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB driver.\n");
out.write("# If you use MariaDB, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + ".\n");
out.write("# How many connections can be awaited for simultaneously, may be useful to increase if SQL database is hosted on a separate machine to account for ping.\n");
out.write("# If it is hosted within the same machine, set it to the count of cores your processor has or the count of threads your processor can process at once.\n");
out.write("thread-pool-size: " + (Runtime.getRuntime().availableProcessors() + 2) + "\n");
out.write("# How long SQL connections should be kept alive in HikariCP. Default: 1800000 (30 minutes)");
out.write("max-connection-lifetime: 1800000");
out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB/PostgreSQL driver.\n");
out.write("# If you use MariaDB or PostgreSQL, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + " or " + "\"org.postgresql.Driver\"" + ".\n");
out.write("sql-driver-class-name: " + "\"default\"" + "\n");
} catch (IOException e) {
e.printStackTrace();

View File

@@ -44,8 +44,7 @@ import java.util.concurrent.Executors;
* @since 0.1.0
*/
public class EffExecuteStatement extends Effect {
private static final ExecutorService threadPool =
Executors.newCachedThreadPool();
private static final ExecutorService threadPool = Executors.newFixedThreadPool(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10));
static String lastError;
static {

View File

@@ -55,7 +55,9 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
}
HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10));
// 30 minutes by default
ds.setMaxLifetime(SkriptDB.getInstance().getConfig().getInt("max-connection-lifetime", 1800000));
//allow specifying of own sql driver class name
if (!SkriptDB.getInstance().getConfig().getString("sql-driver-class-name", "default").equals("default")) {
ds.setDriverClassName(SkriptDB.getInstance().getConfig().getString("sql-driver-class-name"));

View File

@@ -1,5 +1,5 @@
name: skript-db
version: 1.3.5
version: 1.3.9
main: com.btk5h.skriptdb.SkriptDB
depend: [Skript]
authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL]