Completed insert statement
This commit is contained in:
parent
ec5960321e
commit
504630e191
@ -7,7 +7,7 @@
|
|||||||
package dev.salmonllama.fsbot.database;
|
package dev.salmonllama.fsbot.database;
|
||||||
|
|
||||||
import dev.salmonllama.fsbot.config.BotConfig;
|
import dev.salmonllama.fsbot.config.BotConfig;
|
||||||
import dev.salmonllama.fsbot.database.models.OutfitModel;
|
import dev.salmonllama.fsbot.database.models.Outfit;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -38,7 +38,7 @@ public class FSDB {
|
|||||||
|
|
||||||
private static void prepareTables() {
|
private static void prepareTables() {
|
||||||
try {
|
try {
|
||||||
get().query(OutfitModel.schema());
|
get().query(Outfit.schema());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,36 @@
|
|||||||
package dev.salmonllama.fsbot.database.controllers;
|
package dev.salmonllama.fsbot.database.controllers;
|
||||||
|
|
||||||
import dev.salmonllama.fsbot.database.FSDB;
|
import dev.salmonllama.fsbot.database.FSDB;
|
||||||
import dev.salmonllama.fsbot.database.models.OutfitModel;
|
import dev.salmonllama.fsbot.database.models.Outfit;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class OutfitController {
|
public class OutfitController {
|
||||||
public static void insert(OutfitModel outfit) {
|
public static void insert(Outfit outfit) {
|
||||||
try {
|
try {
|
||||||
FSDB.get().insert("INSERT INTO outfits('id', 'link') VALUES (?, ?)", outfit.id, outfit.link);
|
FSDB.get().insert(
|
||||||
|
"INSERT INTO " +
|
||||||
|
"outfits('id', 'link', 'submitter', 'tag', 'created', 'updated', 'deleted', 'featured', 'display_count', 'deletion_hash') " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
outfit.id,
|
||||||
|
outfit.link,
|
||||||
|
outfit.submitter,
|
||||||
|
outfit.tag,
|
||||||
|
outfit.created,
|
||||||
|
outfit.updated,
|
||||||
|
outfit.deleted,
|
||||||
|
outfit.featured,
|
||||||
|
outfit.displayCount,
|
||||||
|
outfit.deletionHash
|
||||||
|
);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OutfitModel findById(String id) throws SQLException {
|
public static Outfit findById(String id) throws SQLException {
|
||||||
OutfitModel outfit = new OutfitModel();
|
Outfit outfit = new Outfit();
|
||||||
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE id = ?", id)) {
|
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE id = ?", id)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
outfit = mapObject(rs);
|
outfit = mapObject(rs);
|
||||||
@ -33,8 +47,8 @@ public class OutfitController {
|
|||||||
return outfit;
|
return outfit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OutfitModel findRandom() throws SQLException {
|
public static Outfit findRandom() throws SQLException {
|
||||||
OutfitModel outfit = new OutfitModel();
|
Outfit outfit = new Outfit();
|
||||||
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE deleted = 0 ORDERBY random() LIMIT 1")) {
|
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE deleted = 0 ORDERBY random() LIMIT 1")) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
outfit = mapObject(rs);
|
outfit = mapObject(rs);
|
||||||
@ -46,8 +60,8 @@ public class OutfitController {
|
|||||||
return outfit;
|
return outfit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OutfitModel findRandomByTag(String tag) {
|
public static Outfit findRandomByTag(String tag) {
|
||||||
OutfitModel outfit = new OutfitModel();
|
Outfit outfit = new Outfit();
|
||||||
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE tag = ? AND deleted = 0 ORDERBY random() LIMIT 1", tag)) {
|
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE tag = ? AND deleted = 0 ORDERBY random() LIMIT 1", tag)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
outfit = mapObject(rs);
|
outfit = mapObject(rs);
|
||||||
@ -59,8 +73,8 @@ public class OutfitController {
|
|||||||
return outfit;
|
return outfit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OutfitModel findRandomBySubmitter(String submitterId) {
|
public static Outfit findRandomBySubmitter(String submitterId) {
|
||||||
OutfitModel outfit = new OutfitModel();
|
Outfit outfit = new Outfit();
|
||||||
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE submitter = ? AND deleted = 0 ORDERBY random() LIMIT 1", submitterId)) {
|
try (ResultSet rs = FSDB.get().select("SELECT * FROM outfits WHERE submitter = ? AND deleted = 0 ORDERBY random() LIMIT 1", submitterId)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
outfit = mapObject(rs);
|
outfit = mapObject(rs);
|
||||||
@ -98,8 +112,8 @@ public class OutfitController {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OutfitModel mapObject(ResultSet rs) throws SQLException {
|
private static Outfit mapObject(ResultSet rs) throws SQLException {
|
||||||
OutfitModel outfit = new OutfitModel();
|
Outfit outfit = new Outfit();
|
||||||
outfit.id = rs.getString("id");
|
outfit.id = rs.getString("id");
|
||||||
outfit.link = rs.getString("link");
|
outfit.link = rs.getString("link");
|
||||||
outfit.tag = rs.getString("tag");
|
outfit.tag = rs.getString("tag");
|
||||||
|
Loading…
Reference in New Issue
Block a user