Add music table, but neglect actually doing something with it
continuous-integration/drone/push Build was killed Details

This commit is contained in:
DutchEllie 2022-08-22 16:15:38 +02:00
parent 62bac12144
commit da55b65a42
Signed by: DutchEllie
SSH Key Fingerprint: SHA256:dKq6ZSgN5E3Viqrw/+xAdf2VdR6hdRGNyrYqXXwfjTY
6 changed files with 59 additions and 8 deletions

View File

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

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;
});
}

View File

@ -1,12 +1,12 @@
import db from "./db";
import type User from "../entities/user";
export function getID(id: number): Promise<User | undefined>{
const user = db().select("*").from<User>("users").where("id", id).first().then((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()
@ -20,6 +20,4 @@ export function createUser(username: string, email: string, website: string, pas
.then((n) => {
return n[0];
});
}
//createUser("quenten", "test@email", "", "password");
};

View File

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

View File

@ -1,5 +1,5 @@
interface User {
id: number,
userid: number,
username: string,
email: string,
password: string,