Skip to content

Commit 3cb2adb

Browse files
Denzel CodeDenzel Code
authored andcommitted
2 parents 785d9c7 + 2f006fa commit 3cb2adb

File tree

1 file changed

+201
-1
lines changed

1 file changed

+201
-1
lines changed

README.md

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ The best Java query builder/SQL connector.
44
## What's AdvancedSQL?
55
AdvancedSQL is a SQL query builder and/or connector that helps you to generate/modify information on the database without even have to write any line of SQL code, which sometimes is kindof boring and tiring. AdvancedSQL is the best exit for that developers who wants to continue coding without having to write out-of-syntax code (SQL queries) on Java code.
66

7-
## Documentation:
7+
## Download
8+
Download the last JAR version: https://github.com/DenzelCode/AdvancedSQL/releases/latest
9+
10+
## Examples:
811
**Connect to the Database:**
912
There is no need to create the database manually, AdvancedSQL does it for you.
1013
```java
@@ -27,6 +30,8 @@ import advancedsql.*;
2730
import advancedsql.query.*;
2831
import advancedsql.table.ITable;
2932

33+
import java.sql.SQLException;
34+
3035
try {
3136
MySQL mySQL = connect();
3237

@@ -59,6 +64,8 @@ import advancedsql.query.*;
5964
import advancedsql.query.action.Add;
6065
import advancedsql.query.action.Modify;
6166

67+
import java.sql.SQLException;
68+
6269
try {
6370
MySQL mySQL = connect();
6471

@@ -89,6 +96,199 @@ try {
8996
}
9097
```
9198

99+
**Insert:**
100+
```java
101+
import advancedsql.*;
102+
import advancedsql.query.*;
103+
104+
import java.sql.SQLException;
105+
import java.util.HashMap;
106+
import java.util.Map;
107+
108+
try {
109+
MySQL mySQL = connect();
110+
111+
// Insert
112+
Insert query = mySQL.table("users").insert(new HashMap<>(){{
113+
put("first_name", "Denzel");
114+
put("last_name", "Code");
115+
}});
116+
int execute = query.execute();
117+
118+
// Print query string and result.
119+
System.out.println(query);
120+
System.out.println(execute);
121+
} catch (SQLException e) {
122+
e.printStackTrace();
123+
}
124+
```
125+
126+
**Update:**
127+
```java
128+
import advancedsql.*;
129+
import advancedsql.query.*;
130+
import java.sql.SQLException;
131+
import java.util.HashMap;
132+
import java.util.Map;
133+
134+
try {
135+
MySQL mySQL = connect();
136+
137+
// Update
138+
Update query = mySQL.table("users").update(new HashMap<>(){{
139+
put("token", "Advanced");
140+
}}).where("first_name = ?", "Denzel");
141+
int execute = query.execute();
142+
143+
// Print query string and result.
144+
System.out.println(query);
145+
System.out.println(execute)p
146+
} catch (SQLException e) {
147+
e.printStackTrace();
148+
}
149+
```
150+
151+
**Select:**
152+
```java
153+
import advancedsql.*;
154+
import advancedsql.query.*;
155+
import java.sql.SQLException;
156+
157+
try {
158+
MySQL mySQL = connect();
159+
160+
// Select
161+
Select query = mySQL.table("users").select();
162+
Map<String, Object> fetch = query.fetch();
163+
164+
// Print query string and result.
165+
System.out.println(query);
166+
System.out.println(fetch);
167+
} catch (SQLException e) {
168+
e.printStackTrace();
169+
}
170+
```
171+
172+
**Select with join:**
173+
```java
174+
import advancedsql.*;
175+
import advancedsql.query.*;
176+
import advancedsql.query.action.Add;
177+
import advancedsql.query.action.Modify;
178+
import advancedsql.table.ITable;
179+
180+
import java.sql.SQLException;
181+
import java.util.HashMap;
182+
import java.util.Map;
183+
184+
try {
185+
MySQL mySQL = connect();
186+
187+
// Create information table
188+
ITable table = mySQL.table("information");
189+
190+
// Delete table if exists.
191+
if (mySQL.table("information").exists()) table.drop().execute();
192+
193+
// Create table
194+
Create create = table.create();
195+
196+
// Table columns
197+
create.id();
198+
create.integer("user_id").nullable();
199+
create.string("address").nullable();
200+
Boolean execute = create.execute();
201+
202+
// Print query and result.
203+
System.out.println(create);
204+
System.out.println(execute);
205+
206+
// Insert value
207+
table.insert(new HashMap<>(){{
208+
put("user_id", 1);
209+
put("address", "20 Cooper Square");
210+
}}).execute();
211+
212+
table = mySQL.table("users");
213+
214+
Select query = table.select(new String[]{"information.address", "users.first_name"})
215+
.innerJoin("information")
216+
.on("users.id = information.user_id")
217+
.where("first_name = ?", "Denzel");
218+
219+
Map<String, Object> user = query.fetch();
220+
221+
// Print query and result.
222+
System.out.println(query);
223+
System.out.println(user);
224+
} catch (SQLException e) {
225+
e.printStackTrace();
226+
}
227+
```
228+
229+
**Delete:**
230+
```java
231+
import advancedsql.*;
232+
import advancedsql.query.*;
233+
import java.sql.SQLException;
234+
235+
try {
236+
MySQL mySQL = connect();
237+
238+
// Delete
239+
Delete query = mySQL.table("users").delete().where("first_name = ?", "Denzel");
240+
int execute = query.execute();
241+
242+
// Print query and result.
243+
System.out.println(query);
244+
System.out.println(execute);
245+
} catch (SQLException e) {
246+
e.printStackTrace();
247+
}
248+
```
249+
250+
**Truncate:**
251+
```java
252+
import advancedsql.*;
253+
import advancedsql.query.*;
254+
import java.sql.SQLException;
255+
256+
try {
257+
MySQL mySQL = connect();
258+
259+
// Truncate table
260+
Truncate query = mySQL.table("users").truncate();
261+
Boolean execute = query.execute();
262+
263+
// Print query and result.
264+
System.out.println(query);
265+
System.out.println(execute);
266+
} catch (SQLException e) {
267+
e.printStackTrace();
268+
}
269+
```
270+
271+
**Drop:**
272+
```java
273+
import advancedsql.*;
274+
import advancedsql.query.*;
275+
import java.sql.SQLException;
276+
277+
try {
278+
MySQL mySQL = connect();
279+
280+
// Drop table
281+
Drop query = mySQL.table("users").drop();
282+
Boolean execute = query.execute();
283+
284+
// Print query and result.
285+
System.out.println(query);
286+
System.out.println(execute);
287+
} catch (SQLException e) {
288+
e.printStackTrace();
289+
}
290+
```
291+
92292
## Licensing information
93293
This project is licensed under LGPL-3.0. Please see the [LICENSE](/LICENSE) file for details.
94294

0 commit comments

Comments
 (0)