Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Govindas | c11980eea5 | |
Govindas | 4124994b83 |
11
README.md
11
README.md
|
@ -8,10 +8,10 @@
|
|||
- 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
|
||||
- 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
|
||||
- SQL Driver is configurable both in config and in database connection, 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.
|
||||
|
@ -26,7 +26,7 @@ Stores the connection information for a data source. This should be saved to a v
|
|||
MariaDB/PostgreSQL users: make sure to check `config.yml` to use the correct driver.
|
||||
#### Syntax
|
||||
```
|
||||
[the] data(base|[ ]source) [(of|at)] %string%
|
||||
[the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%] [[(using|with)] [a] driver %-string%]
|
||||
```
|
||||
|
||||
#### Examples
|
||||
|
@ -35,6 +35,10 @@ set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password
|
|||
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"
|
||||
|
||||
# Extra parameters:
|
||||
set {sql} to the database "postgresql://localhost:3306/mydatabase?user=admin&password=12345&ssl=false" with a maximum connection lifetime of 30 minutes
|
||||
set {sql} to the database "postgresql://localhost:3306/mydatabase?user=admin&password=12345&ssl=false" with a maximum connection lifetime of 30 minutes using driver "org.postgresql.Driver"
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -76,6 +80,7 @@ Stores the error from the last executed statement, if there was one.
|
|||
|
||||
### Expression `Unsafe Expression` => `text`
|
||||
Opts out of automatic SQL injection protection for a specific expression in a statement.
|
||||
Note: If using PostgreSQL, this will always be needed, due to skript-db not supporting SQL injection protection for PostgreSQL currently.
|
||||
#### Syntax
|
||||
```
|
||||
unsafe %text%
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>com.btk5h</groupId>
|
||||
<artifactId>skript-db</artifactId>
|
||||
<version>1.3.9</version>
|
||||
<version>1.4.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<repositories>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</repository>
|
||||
<repository>
|
||||
<id>sk89q</id>
|
||||
<url>http://maven.sk89q.com/repo</url>
|
||||
<url>https://maven.sk89q.com/repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
@ -100,14 +100,14 @@
|
|||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>3.0.9</version>
|
||||
<version>3.1.2</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>
|
||||
<version>42.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.Map;
|
|||
*
|
||||
* @name Data Source
|
||||
* @index -1
|
||||
* @pattern [the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%]"
|
||||
* @pattern [the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%] [[(using|with)] [a] driver %-string%]"
|
||||
* @return datasource
|
||||
* @example set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
|
||||
* @since 0.1.0
|
||||
|
@ -33,11 +33,12 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
|
|||
static {
|
||||
Skript.registerExpression(ExprDataSource.class, HikariDataSource.class,
|
||||
ExpressionType.COMBINED, "[the] data(base|[ ]source) [(of|at)] %string% " +
|
||||
"[with [a] [max[imum]] [connection] life[ ]time of %-timespan%]");
|
||||
"[with [a] [max[imum]] [connection] life[ ]time of %-timespan%] " + "[[(using|with)] [a] driver %-string%]");
|
||||
}
|
||||
|
||||
private Expression<String> url;
|
||||
private Expression<Timespan> maxLifetime;
|
||||
private Expression<String> driver;
|
||||
|
||||
@Override
|
||||
protected HikariDataSource[] get(Event e) {
|
||||
|
@ -56,12 +57,17 @@ 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")) {
|
||||
|
||||
// Allow specifying of own sql driver class name
|
||||
if (driver != null && driver.getSingle(e) != null) {
|
||||
ds.setDriverClassName(driver.getSingle(e));
|
||||
} else if (!SkriptDB.getInstance().getConfig().getString("sql-driver-class-name", "default").equals("default")) {
|
||||
ds.setDriverClassName(SkriptDB.getInstance().getConfig().getString("sql-driver-class-name"));
|
||||
}
|
||||
|
||||
ds.setJdbcUrl(jdbcUrl);
|
||||
|
||||
if (maxLifetime != null) {
|
||||
|
@ -98,6 +104,7 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
|
|||
SkriptParser.ParseResult parseResult) {
|
||||
url = (Expression<String>) exprs[0];
|
||||
maxLifetime = (Expression<Timespan>) exprs[1];
|
||||
driver = (Expression<String>) exprs[2];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: skript-db
|
||||
version: 1.3.9
|
||||
version: 1.4.0
|
||||
main: com.btk5h.skriptdb.SkriptDB
|
||||
depend: [Skript]
|
||||
authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL]
|
||||
|
|
Loading…
Reference in New Issue