Add music table, but neglect actually doing something with it
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
62bac12144
commit
da55b65a42
@ -3,7 +3,7 @@ import type { Knex } from "knex";
|
|||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
export async function up(knex: Knex): Promise<void> {
|
||||||
return knex.schema.createTable("users", (table) => {
|
return knex.schema.createTable("users", (table) => {
|
||||||
table.increments("id", { primaryKey: true });
|
table.increments("userid", { primaryKey: true });
|
||||||
table.string("username", 255).notNullable;
|
table.string("username", 255).notNullable;
|
||||||
table.string("email", 255).notNullable;
|
table.string("email", 255).notNullable;
|
||||||
table.string("password", 64).notNullable;
|
table.string("password", 64).notNullable;
|
||||||
|
18
src/lib/db/migrations/20220822134642_create-music-table.ts
Normal file
18
src/lib/db/migrations/20220822134642_create-music-table.ts
Normal 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
26
src/lib/db/music.ts
Normal 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;
|
||||||
|
});
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
import db from "./db";
|
import db from "./db";
|
||||||
import type User from "../entities/user";
|
import type User from "../entities/user";
|
||||||
|
|
||||||
export function getID(id: number): Promise<User | undefined>{
|
export function getID(userid: number): Promise<User | undefined>{
|
||||||
const user = db().select("*").from<User>("users").where("id", id).first().then((user) => {
|
const user = db().select("*").from<User>("users").where("userid", userid).first().then((user) => {
|
||||||
return user;
|
return user;
|
||||||
});
|
});
|
||||||
return user;
|
return user;
|
||||||
}
|
};
|
||||||
|
|
||||||
export function createUser(username: string, email: string, website: string, password: string): Promise<number> {
|
export function createUser(username: string, email: string, website: string, password: string): Promise<number> {
|
||||||
return db()
|
return db()
|
||||||
@ -20,6 +20,4 @@ export function createUser(username: string, email: string, website: string, pas
|
|||||||
.then((n) => {
|
.then((n) => {
|
||||||
return n[0];
|
return n[0];
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
//createUser("quenten", "test@email", "", "password");
|
|
||||||
|
9
src/lib/entities/music.ts
Normal file
9
src/lib/entities/music.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
interface Music {
|
||||||
|
musicID?: number;
|
||||||
|
ytlink: string;
|
||||||
|
userID: number;
|
||||||
|
created_at?: Date,
|
||||||
|
updated_at?: Date,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Music;
|
@ -1,5 +1,5 @@
|
|||||||
interface User {
|
interface User {
|
||||||
id: number,
|
userid: number,
|
||||||
username: string,
|
username: string,
|
||||||
email: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
|
Loading…
Reference in New Issue
Block a user