Built basic blog backend.

This commit is contained in:
2018-11-20 08:39:25 +11:00
parent 75764f744d
commit 8ab9f09287
34 changed files with 221 additions and 98 deletions

View File

@ -68,12 +68,13 @@ class DatabaseConnection {
let keys = Object.keys(queries);
for(let i = 0; i < keys.length; i++) {
let k = keys[i];
if(!k.startsWith("Create")) return;
if(!k.toLowerCase().startsWith("create")) continue;
await this.none(k);
};
}
getQuery(name) {
if(!this.queries[name]) throw new Error("No Query by that name exists");
return this.queries[name];
}

View File

@ -0,0 +1,35 @@
// Copyright (c) 2018 Dominic Masters
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const CacheStore = require('./../cache/CacheStore');
module.exports = class DatabaseInterface {
constructor(app) {
this.app = app;
this.store = new CacheStore(app);
}
getApp() {return this.app;}
getDatabase() {return this.app.getDatabase();}
getStore() {return this.store;}
}

View File

@ -0,0 +1,5 @@
INSERT INTO "BlogArticles" (
"handle", "image", "shortDescription", "description", "date"
) VALUES (
${handle}, ${image}, ${shortDescription}, ${description}, ${date}
) RETURNING *;

View File

@ -0,0 +1 @@
SELECT * FROM "BlogArticles" WHERE "handle"=${handle};

View File

@ -0,0 +1 @@
SELECT * FROM "BlogArticles" WHERE "id" = ${id};

View File

@ -0,0 +1,11 @@
SELECT
*
FROM
"BlogArticles"
ORDER BY
"date" DESC
LIMIT
${count}
OFFSET
${offset}
;

View File

@ -0,0 +1 @@
SELECT COUNT(*) FROM "BlogArticles";

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS "BlogArticles" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"handle" TEXT NOT NULL UNIQUE,
"title" TEXT NOT NULL,
"image" TEXT NOT NULL,
"shortDescription" TEXT NULL,
"description" TEXT NOT NULL,
"date" TIMESTAMP NOT NULL
);

View File

@ -1,5 +0,0 @@
CREATE TABLE IF NOT EXISTS "Formats" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"gameId" BIGSERIAL NOT NULL
);

View File

@ -1,4 +0,0 @@
CREATE TABLE IF NOT EXISTS "Games" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL UNIQUE
);

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS "Seasons" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"formatId" BIGSERIAL NOT NULL,
"startDate" TIMESTAMP NOT NULL,
"endDate" TIMESTAMP NOT NULL
);

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS "TeamUsersSeasons" (
"teamId" BIGSERIAL NOT NULL,
"userId" BIGSERIAL NOT NULL,
"seasonId" BIGSERIAL NOT NULL,
"registered" TIMESTAMP NOT NULL,
PRIMARY KEY("teamId", "userId", "seasonId")
);

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS "Teams" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"name" varchar(32) NOT NULL UNIQUE,
"motto" text NULL,
"image" text NULL,
"registered" TIMESTAMP NOT NULL
);

View File

@ -1,6 +0,0 @@
CREATE TABLE IF NOT EXISTS "Users" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"discordId" text NULL UNIQUE,
"steamId" text NULL UNIQUE,
"email" text NULL UNIQUE
);

View File

@ -1 +0,0 @@
INSERT INTO "Formats" ("name", "gameId") VALUES (${name}, ${gameId}) RETURNING *;

View File

@ -1 +0,0 @@
SELECT * FROM "Formats" WHERE "gameId"=${gameId};

View File

@ -1 +0,0 @@
INSERT INTO "Games" (name) VALUES (${name}) RETURNING *;

View File

@ -1 +0,0 @@
SELECT * FROM "Games" WHERE LOWER("name") = LOWER(${name}) LIMIT 1;

View File

@ -1 +0,0 @@
SELECT * FROM "Season" WHERE id = ${id} LIMIT 1;

View File

@ -1,5 +0,0 @@
SELECT * FROM "Seasons"
WHERE
"startDate" <= ${date} AND
"endDate" >= ${date}
LIMIT 1;

View File

@ -1,5 +0,0 @@
INSERT INTO "Teams" (
"name", "motto", "image", "registered"
) VALUES (
${name}, ${motto}, ${image}, ${registered}
) RETURNING *;

View File

@ -1,5 +0,0 @@
INSERT INTO "TeamUsersSeasons" (
"teamId", "userId", "seasonId", "registered"
) VALUES (
${teamId}, ${userId}, ${seasonId}, ${registered}
) RETURNING *;

View File

@ -1 +0,0 @@
SELECT * FROM "Teams" WHERE "id"=${id} LIMIT 1;

View File

@ -1 +0,0 @@
SELECT * FROM "Teams" WHERE LOWER("name") = LOWER(${name}) LIMIT 1;

View File

@ -1,10 +0,0 @@
SELECT
*
FROM
"Teams"
INNER JOIN
"TeamUsersSeasons" ON "TeamUsersSeasons"."teamId" = "Teams"."id"
WHERE
"TeamUsersSeasons"."userId" = ${userId} AND
"TeamUsersSeasons"."seasonId" = ${seasonId}
LIMIT 1;

View File

@ -1 +0,0 @@
SELECT * FROM "TeamUsersSeasons" WHERE "teamId" = ${teamId};

View File

@ -1,11 +0,0 @@
SELECT
"Teams".*
FROM
"Teams"
INNER JOIN
"TeamUsersSeasons" ON "TeamUsersSeasons"."teamId" = "Teams"."id"
WHERE
"TeamUsersSeasons"."seasonId" = ${seasonId}
GROUP BY
"Teams"."id"
;

View File

@ -1,9 +0,0 @@
INSERT INTO "Users" (
"discordId",
"steamId",
"email"
) VALUES (
${discordId},
${steamId},
${email}
) RETURNING *;

View File

@ -1 +0,0 @@
SELECT * FROM "Users" WHERE "discordId" = ${discordId} LIMIT 1;

View File

@ -1 +0,0 @@
SELECT * FROM "Users" WHERE "id"=${id} LIMIT 1;