├── .gitignore
├── README.md
├── memory
├── pom.xml
└── src
├── main
└── java
│ └── io
│ └── github
│ └── eikefs
│ └── sql
│ └── provider
│ ├── Provider.java
│ ├── database
│ └── Database.java
│ ├── orm
│ ├── Model.java
│ ├── ORM.java
│ └── annotations
│ │ ├── Field.java
│ │ └── Table.java
│ └── query
│ ├── Query.java
│ ├── TableQuery.java
│ ├── field
│ └── TableField.java
│ └── type
│ ├── OrderType.java
│ └── WhereType.java
└── test
└── java
└── io
└── github
└── eikefs
└── sql
└── provider
└── test
├── QueriesTest.java
└── orm
├── ModelTests.java
├── ORMTest.java
└── User.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | target
3 | *.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sql-provider
2 | A easy way to use SQL on Java. Create new connections and easy queries.
3 |
4 | # Creating database-connections
5 |
6 | ```java
7 | Database database = Provider.getInstance().submit(url, user, password); // Or Provider.getInstance().submit(url)
8 | ```
9 |
10 | # Creating tables
11 |
12 | ```java
13 | Database#update(new TableQuery()
14 | .name("users", true)
15 | .fields(new TableField()
16 | .name("id")
17 | .type("int")
18 | .size(8)
19 | .autoIncrement())
20 | .primary("id"));
21 | ```
22 |
23 | And others examples you may get on `QueriesTest.java` file, on test folder.
24 |
25 | # How to install
26 |
27 | ```xml
28 |
29 | jitpack.io
30 | https://jitpack.io
31 |
32 | ```
33 |
34 | ```xml
35 |
36 | com.github.eikefs
37 | sql-provider
38 | 1.0.1
39 |
40 | ```
41 |
42 |
--------------------------------------------------------------------------------
/memory:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eikefs/sql-provider/7ac00d565364573f5114feaa7ae7ffe3e95da7a2/memory
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | io.github.eikefs
8 | sql-provider
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 8
17 | 8
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.mockito
26 | mockito-all
27 | 2.0.2-beta
28 | test
29 |
30 |
31 |
32 | junit
33 | junit
34 | 4.13.1
35 | test
36 |
37 |
38 |
39 | mysql
40 | mysql-connector-java
41 | 8.0.16
42 |
43 |
44 |
45 | org.xerial
46 | sqlite-jdbc
47 | 3.8.11.2
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/java/io/github/eikefs/sql/provider/Provider.java:
--------------------------------------------------------------------------------
1 | package io.github.eikefs.sql.provider;
2 |
3 | import io.github.eikefs.sql.provider.database.Database;
4 |
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 |
8 | public class Provider {
9 |
10 | private Provider() {}
11 |
12 | private static final Provider instance = new Provider();
13 |
14 | public static Provider getInstance() {
15 | return instance;
16 | }
17 |
18 | private Connection newConnection(String url) {
19 | try {
20 | Class.forName("org.sqlite.JDBC");
21 |
22 | url = url.startsWith("jdbc:sqlite:") ? url : "jdbc:sqlite:" + url;
23 |
24 | return DriverManager.getConnection(url);
25 | } catch (Exception e) {
26 | e.printStackTrace();
27 | }
28 |
29 | return null;
30 | }
31 |
32 | private Connection newConnection(String url, String user, String pass) {
33 | try {
34 | Class.forName("com.mysql.cj.jdbc.Driver");
35 |
36 | url = url.startsWith("jdbc:mysql://") ? "jdbc:mysql://" + url : url;
37 |
38 | return DriverManager.getConnection(url, user, pass);
39 | } catch (Exception e) {
40 | e.printStackTrace();
41 | }
42 |
43 | return null;
44 | }
45 |
46 | public Database submit(String url) {
47 | return new Database(newConnection(url));
48 | }
49 |
50 | public Database submit(String url, String user, String pass) {
51 | return new Database(newConnection(url, user, pass));
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/io/github/eikefs/sql/provider/database/Database.java:
--------------------------------------------------------------------------------
1 | package io.github.eikefs.sql.provider.database;
2 |
3 | import io.github.eikefs.sql.provider.query.Query;
4 |
5 | import java.lang.reflect.Constructor;
6 | import java.sql.Connection;
7 | import java.sql.PreparedStatement;
8 | import java.sql.ResultSet;
9 | import java.util.*;
10 | import java.util.concurrent.CompletableFuture;
11 |
12 | public class Database {
13 |
14 | private final Connection connection;
15 |
16 | public Database(Connection connection) {
17 | this.connection = Objects.requireNonNull(connection);
18 | }
19 |
20 | public CompletableFuture> query(Query query) {
21 | return query(query.raw());
22 | }
23 |
24 | public CompletableFuture> query(String query) {
25 | return CompletableFuture.supplyAsync(() -> querySync(query));
26 | }
27 |
28 | public List