summaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
authorJulien Dessaux2023-01-05 02:09:07 +0100
committerJulien Dessaux2023-01-05 02:09:07 +0100
commitd7ed1196bdd44d7734d41d91a5e72a71785e0a08 (patch)
treeaafae6571d5154dc5e9a061c8f54ca8e9b1287ad /database
parentAdded more tests (diff)
downloadjeux-de-mots-d7ed1196bdd44d7734d41d91a5e72a71785e0a08.tar.gz
jeux-de-mots-d7ed1196bdd44d7734d41d91a5e72a71785e0a08.tar.bz2
jeux-de-mots-d7ed1196bdd44d7734d41d91a5e72a71785e0a08.zip
switched to single quotes string in eslint
Diffstat (limited to 'database')
-rw-r--r--database/db.js18
-rw-r--r--database/games.js8
-rw-r--r--database/users.js10
3 files changed, 18 insertions, 18 deletions
diff --git a/database/db.js b/database/db.js
index 1e8b50d..1d8a3f0 100644
--- a/database/db.js
+++ b/database/db.js
@@ -1,27 +1,27 @@
-import fs from "fs";
-import Database from "better-sqlite3";
+import fs from 'fs';
+import Database from 'better-sqlite3';
const allMigrations = [
- "database/000_init.sql",
- "database/001_games.sql",
+ 'database/000_init.sql',
+ 'database/001_games.sql',
];
const db = new Database(
- process.env.NODE_ENV === "test" ? "testjdm.db" : "jdm.db",
- process.env.NODE_ENV === "development" ? { verbose: console.log } : null
+ process.env.NODE_ENV === 'test' ? 'testjdm.db' : 'jdm.db',
+ process.env.NODE_ENV === 'development' ? { verbose: console.log } : null
);
-db.pragma("foreign_keys = ON");
+db.pragma('foreign_keys = ON');
db.transaction(function migrate() {
let version;
try {
- version = db.prepare("SELECT version FROM schema_version").get().version;
+ version = db.prepare('SELECT version FROM schema_version').get().version;
} catch {
version = 0;
}
if (version === allMigrations.length) return;
while (version < allMigrations.length) {
- db.exec(fs.readFileSync(allMigrations[version], "utf8"));
+ db.exec(fs.readFileSync(allMigrations[version], 'utf8'));
version++;
}
db.exec(`DELETE FROM schema_version; INSERT INTO schema_version (version) VALUES (${version});`);
diff --git a/database/games.js b/database/games.js
index 3517d0a..ac9a4ad 100644
--- a/database/games.js
+++ b/database/games.js
@@ -1,8 +1,8 @@
-import db from "./db.js";
+import db from './db.js';
-const getGameStatement = db.prepare("SELECT * from games where id = ?;");
-const listGamesStatement = db.prepare("SELECT * from games where player1 = ?1 OR player2 = ?1 ORDER BY last_move_at;");
-const newGameStatement = db.prepare("INSERT INTO games (player1, player2, data) VALUES (?, ?, ?);");
+const getGameStatement = db.prepare('SELECT * from games where id = ?;');
+const listGamesStatement = db.prepare('SELECT * from games where player1 = ?1 OR player2 = ?1 ORDER BY last_move_at;');
+const newGameStatement = db.prepare('INSERT INTO games (player1, player2, data) VALUES (?, ?, ?);');
export function getGame(id) {
try {
diff --git a/database/users.js b/database/users.js
index b24e3b4..cc50bdc 100644
--- a/database/users.js
+++ b/database/users.js
@@ -1,12 +1,12 @@
-import bcrypt from "bcrypt";
+import bcrypt from 'bcrypt';
-import db from "./db.js";
+import db from './db.js';
const saltRounds = 10;
-const createUserStatement = db.prepare("INSERT INTO users (username, hash, email) VALUES (?, ?, ?);");
-const getUserByUsernameStatement = db.prepare("SELECT id, username, email from users WHERE username = ?;");
-const loginStatement = db.prepare("SELECT id, username, hash, email FROM users WHERE username = ?;");
+const createUserStatement = db.prepare('INSERT INTO users (username, hash, email) VALUES (?, ?, ?);');
+const getUserByUsernameStatement = db.prepare('SELECT id, username, email from users WHERE username = ?;');
+const loginStatement = db.prepare('SELECT id, username, hash, email FROM users WHERE username = ?;');
export async function createUser(username, password, email) {
const hash = await bcrypt.hash(password, saltRounds);