Compare commits

...

2 Commits

Author SHA1 Message Date
DutchEllie da55b65a42
Add music table, but neglect actually doing something with it
continuous-integration/drone/push Build was killed Details
2022-08-22 16:15:38 +02:00
DutchEllie 62bac12144
Simple database concept 2022-08-20 13:13:40 +02:00
15 changed files with 1807 additions and 172 deletions

View File

@ -1,3 +1,8 @@
apiVersion: v2
name: newsite
version: v0.0.3
version: v0.0.4
dependencies:
- name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 11.1.8

View File

@ -27,3 +27,15 @@ ingress:
paths:
- path: /
pathType: Prefix
mariadb:
auth:
database: website
username: ellie
password: ellie
rootPassword: ellie
primary:
service:
port: 3306
persistence:
size: 3Gi

View File

@ -1,6 +1,8 @@
baseURL: changeme.dutchellie.nl
name: changeme-prod
containerEnv:
- name: NODE_ENV
value: production
# - name: APIURL
# value: https://api.quenten.nl/api
service:

View File

@ -1,6 +1,8 @@
baseURL: changemestaging.dutchellie.nl
name: changeme-staging
containerEnv:
- name: NODE_ENV
value: staging
# - name: APIURL
# value: https://api.quenten.nl/api/testing
service:

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ node_modules
.env
.env.*
!.env.example
*.sqlite3

1776
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,8 @@
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
"format": "prettier --write --plugin-search-dir=. ."
"format": "prettier --write --plugin-search-dir=. .",
"knex": "node --loader ts-node/esm node_modules/.bin/knex --knexfile src/lib/db/knexfile.ts"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
@ -38,7 +39,11 @@
"type": "module",
"dependencies": {
"js-sha256": "^0.9.0",
"knex": "^2.2.0",
"mysql2": "^2.3.3",
"sqlite3": "^5.0.11",
"svelte-gestures": "^1.4.1",
"svelte-language-server": "^0.14.29"
"svelte-language-server": "^0.14.29",
"ts-node": "^10.9.1"
}
}

8
src/lib/db/db.ts Normal file
View File

@ -0,0 +1,8 @@
import knex from "knex";
import configs from "./knexfile";
const config = configs[process.env.NODE_ENV || "development"];
const db = knex(config);
export default db;

54
src/lib/db/knexfile.ts Normal file
View File

@ -0,0 +1,54 @@
import type { Knex } from "knex";
// Update with your config settings.
const config: { [key: string]: Knex.Config } = {
development: {
client: "sqlite3",
connection: {
filename: "/home/quenten/Documents/repos/dutchellie.nl/DutchEllie/svelte-website/src/lib/db/dev.sqlite3"
},
debug: true,
useNullAsDefault: true,
migrations: {
extension: 'ts',
}
},
staging: {
client: "mysql",
connection: {
database: "website_staging",
user: "ellie",
password: "ellie"
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations",
extension: 'ts',
}
},
production: {
client: "mysql",
connection: {
database: "website",
user: "ellie",
password: "ellie"
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations",
extension: 'ts',
}
}
};
export default config;

View File

@ -0,0 +1,19 @@
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable("users", (table) => {
table.increments("userid", { primaryKey: true });
table.string("username", 255).notNullable;
table.string("email", 255).notNullable;
table.string("password", 64).notNullable;
table.string("website", 255);
table.timestamps(true, true);
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.dropTable("users");
}

View File

@ -0,0 +1,18 @@
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable("music", (table) => {
table.increments("musicid", { primaryKey: true });
table.string("ytlink", 255);
table.integer("userid");
table.foreign("userid").references("userid").inTable("users");
table.timestamps(true, true);
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.dropTable("music");
}

26
src/lib/db/music.ts Normal file
View File

@ -0,0 +1,26 @@
import db from "./db";
import type User from "../entities/user";
import type Music from "../entities/music";
export function addSong(link: string, userid: number): Promise<number> {
const song: Music = {
ytlink: link,
userID: userid,
};
return db()
.insert(song)
.into("music")
.then((v) => {
return v[0];
});
}
export function getSongsByUserID(userid: number): Promise<Music[]> {
return db()
.select("*")
.from<Music>("music")
.where("userid", userid)
.then((v) => {
return v;
});
}

23
src/lib/db/user.ts Normal file
View File

@ -0,0 +1,23 @@
import db from "./db";
import type User from "../entities/user";
export function getID(userid: number): Promise<User | undefined>{
const user = db().select("*").from<User>("users").where("userid", userid).first().then((user) => {
return user;
});
return user;
};
export function createUser(username: string, email: string, website: string, password: string): Promise<number> {
return db()
.insert({
username: username,
email: email,
website: website,
password: password,
})
.into("users")
.then((n) => {
return n[0];
});
};

View File

@ -0,0 +1,9 @@
interface Music {
musicID?: number;
ytlink: string;
userID: number;
created_at?: Date,
updated_at?: Date,
}
export default Music;

11
src/lib/entities/user.ts Normal file
View File

@ -0,0 +1,11 @@
interface User {
userid: number,
username: string,
email: string,
password: string,
website?: string,
created_at: Date,
updated_at: Date,
};
export default User;