Skip to content

Commit 437bd70

Browse files
authored
Update README.md
1 parent 07197ea commit 437bd70

File tree

1 file changed

+120
-1
lines changed

1 file changed

+120
-1
lines changed

README.md

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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+
## Examples:
88
**Connect to the Database:**
99
There is no need to create the database manually, AdvancedSQL does it for you.
1010
```java
@@ -89,6 +89,125 @@ try {
8989
}
9090
```
9191

92+
**Insert:**
93+
```java
94+
import advancedsql.*;
95+
import advancedsql.query.*;
96+
97+
try {
98+
MySQL mySQL = connect();
99+
100+
// Insert
101+
Insert query = mySQL.table("users").insert(new HashMap<>(){{
102+
put("first_name", "Denzel");
103+
put("last_name", "Code");
104+
}});
105+
int execute = query.execute();
106+
107+
// Print query string and result.
108+
System.out.println(query);
109+
System.out.println(execute);
110+
111+
assertEquals(1, execute);
112+
} catch (SQLException e) {
113+
e.printStackTrace();
114+
}
115+
```
116+
117+
**Update:**
118+
```java
119+
import advancedsql.*;
120+
import advancedsql.query.*;
121+
122+
try {
123+
MySQL mySQL = connect();
124+
125+
// Update
126+
Update query = mySQL.table("users").update(new HashMap<>(){{
127+
put("token", "Advanced");
128+
}}).where("first_name = ?", "Denzel");
129+
int execute = query.execute();
130+
131+
// Print query string and result.
132+
System.out.println(query);
133+
System.out.println(execute);
134+
135+
assertEquals(1, execute);
136+
} catch (SQLException e) {
137+
e.printStackTrace();
138+
}
139+
```
140+
141+
**Select:**
142+
```java
143+
import advancedsql.*;
144+
import advancedsql.query.*;
145+
146+
try {
147+
MySQL mySQL = connect();
148+
149+
// Select
150+
Select query = mySQL.table("users").select();
151+
Map<String, Object> fetch = query.fetch();
152+
153+
// Print query string and result.
154+
System.out.println(query);
155+
System.out.println(fetch);
156+
} catch (SQLException e) {
157+
e.printStackTrace();
158+
}
159+
```
160+
161+
**Select with join:**
162+
```java
163+
import advancedsql.*;
164+
import advancedsql.query.*;
165+
166+
try {
167+
MySQL mySQL = connect();
168+
169+
// Create information table
170+
ITable table = mySQL.table("information");
171+
172+
// Delete table if exists.
173+
if (mySQL.table("information").exists()) table.drop().execute();
174+
175+
// Create table
176+
Create create = table.create();
177+
178+
// Table columns
179+
create.id();
180+
create.integer("user_id").nullable();
181+
create.string("address").nullable();
182+
Boolean execute = create.execute();
183+
184+
// Print query and result.
185+
System.out.println(create);
186+
System.out.println(execute);
187+
188+
// Insert value
189+
table.insert(new HashMap<>(){{
190+
put("user_id", 1);
191+
put("address", "20 Cooper Square");
192+
}}).execute();
193+
194+
table = mySQL.table("users");
195+
196+
Select query = table.select(new String[]{"information.address", "users.first_name"})
197+
.innerJoin("information")
198+
.on("users.id = information.user_id")
199+
.where("first_name = ?", "Denzel");
200+
201+
Map<String, Object> user = query.fetch();
202+
203+
// Print query and result.
204+
System.out.println(query);
205+
System.out.println(user);
206+
} catch (SQLException e) {
207+
e.printStackTrace();
208+
}
209+
```
210+
92211
## Licensing information
93212
This project is licensed under LGPL-3.0. Please see the [LICENSE](/LICENSE) file for details.
94213

0 commit comments

Comments
 (0)