Separate client and server codes. Keep everything in one git repo for simplicity
[vchess.git] / server / models / Variant.js
diff --git a/server/models/Variant.js b/server/models/Variant.js
new file mode 100644 (file)
index 0000000..233d938
--- /dev/null
@@ -0,0 +1,36 @@
+var db = require("../utils/database");
+
+/*
+ * Structure:
+ *   id: integer
+ *   name: varchar
+ *   description: varchar
+ */
+
+const VariantModel =
+{
+       getByName: function(name, callback)
+       {
+               db.serialize(function() {
+                       const query =
+                               "SELECT * " +
+                               "FROM Variants " +
+                               "WHERE name='" + name + "'";
+                       db.get(query, callback);
+               });
+       },
+
+       getAll: function(callback)
+       {
+               db.serialize(function() {
+                       const query =
+                               "SELECT * " +
+                               "FROM Variants";
+                       db.all(query, callback);
+               });
+       },
+
+       //create, update, delete: directly in DB
+}
+
+module.exports = VariantModel;