Auto Creation Of Tables and Database

This commit is contained in:
Hax 2019-10-27 15:31:29 +01:00
parent 1d0d854ebf
commit 441c31a164
2 changed files with 21 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package com.bbn.hadder;
import com.rethinkdb.RethinkDB;
import com.rethinkdb.gen.exc.ReqlOpFailedError;
import com.rethinkdb.net.Connection;
import com.rethinkdb.net.Cursor;
import com.google.gson.JsonParser;
@ -70,4 +71,23 @@ public class Rethink {
} catch (ClassCastException ignored) {}
return out;
}
public static void setup() {
try {
r.dbCreate("Hadder").run(conn);
} catch (ReqlOpFailedError e) {
System.out.println(e.getMessage());
}
try {
r.tableCreate("server").run(conn);
} catch (ReqlOpFailedError e) {
System.out.println(e.getMessage());
}
try {
r.tableCreate("user").run(conn);
} catch (ReqlOpFailedError e) {
System.out.println(e.getMessage());
}
}
}

View file

@ -11,6 +11,7 @@ public class ReadyListener extends ListenerAdapter {
@Override
public void onReady(@Nonnull ReadyEvent event) {
Rethink.setup();
for (Guild g : event.getJDA().getGuilds()) {
Rethink.insertServer(g.getId());
}