Skip to content

Commit

Permalink
db.d: improve SQL query formatting
Browse files Browse the repository at this point in the history
Avoid putting excessive whitespace into the queries.
  • Loading branch information
mathiascode committed Jan 3, 2025
1 parent 1101e69 commit 262e79d
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/db.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ class Sdb
format!("Cannot create database file %s")(filename));

const users_sql = format!(
"CREATE TABLE IF NOT EXISTS %s(
username TEXT PRIMARY KEY,
password TEXT,
speed INTEGER,
ulnum INTEGER,
files INTEGER,
folders INTEGER,
banned INTEGER,
privileges INTEGER
) WITHOUT ROWID;")(
"CREATE TABLE IF NOT EXISTS %s("
~ " username TEXT PRIMARY KEY,"
~ " password TEXT,"
~ " speed INTEGER,"
~ " ulnum INTEGER,"
~ " files INTEGER,"
~ " folders INTEGER,"
~ " banned INTEGER,"
~ " privileges INTEGER"
~ ") WITHOUT ROWID;")(
users_table
);

const admins_sql = format!(
"CREATE TABLE IF NOT EXISTS %s(
username TEXT PRIMARY KEY,
level INTEGER
) WITHOUT ROWID;")(
"CREATE TABLE IF NOT EXISTS %s("
~ " username TEXT PRIMARY KEY,"
~ " level INTEGER"
~ ") WITHOUT ROWID;")(
admins_table
);

Expand All @@ -81,10 +81,10 @@ class Sdb
private void init_config()
{
const sql = format!(
"CREATE TABLE IF NOT EXISTS %s(
option TEXT PRIMARY KEY,
value
) WITHOUT ROWID;")(
"CREATE TABLE IF NOT EXISTS %s("
~ " option TEXT PRIMARY KEY,"
~ " value"
~ ") WITHOUT ROWID;")(
config_table
);
query(sql);
Expand Down Expand Up @@ -248,9 +248,9 @@ class Sdb
blue ~ username ~ norm
);
const sql = format!(
"SELECT speed,ulnum,files,folders
FROM %s
WHERE username = '%s';")(
"SELECT speed,ulnum,files,folders"
~ " FROM %s"
~ " WHERE username = '%s';")(
users_table, escape(username)
);
const res = query(sql);
Expand Down

0 comments on commit 262e79d

Please sign in to comment.