Skip to content

Commit 100d47a

Browse files
committed
fix: create table if not exists.
1 parent 862db09 commit 100d47a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/com/code/advancedsql/query/Create.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class Create extends ExecuteStatement<Create> {
1919

2020
private final Action action = new Regular();
2121

22+
private boolean ifNotExists = false;
23+
2224
public Create(ITable table) {
2325
super(table);
2426
}
@@ -315,9 +317,16 @@ public Base column(java.lang.String name, String content) {
315317
return this.action.column(name, content);
316318
}
317319

320+
/**
321+
* Create table if not exists.
322+
*/
323+
public void ifNotExists() {
324+
this.ifNotExists = true;
325+
}
326+
318327
@Override
319328
public java.lang.String toQuery() {
320-
StringBuilder query = new StringBuilder("CREATE TABLE " + this.table + " ( ");
329+
StringBuilder query = new StringBuilder("CREATE TABLE " + (ifNotExists ? "IF NOT EXISTS" : "") + this.table + " ( ");
321330

322331
List<IColumn> columns = this.action.getColumns();
323332

0 commit comments

Comments
 (0)