1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { sqlite } from "https://esm.town/v/std/sqlite";
import { sql } from "npm:drizzle-orm";
import { drizzle } from "npm:drizzle-orm/libsql";
import { integer, sqliteTable, text } from "npm:drizzle-orm/sqlite-core";
type Track = {
id: number | null;
artist: string;
title: string;
track_id: string | null;
};
const favorites = [
{ artist: "New Order", title: "Blue Monday" },
{ artist: "New Order", title: "Ceremony" },
{ artist: "New Order", title: "True Faith" },
{ artist: "Pixies", title: "Velouria" },
{ artist: "Stone Roses", title: "Fools Gold" },
{ artist: "Primal Scream", title: "Higher than the Sun" },
] as Track[];
export default async function(interval: Interval) {
await sqlite.execute(`drop table if exists favorite_song_searches;`);
await sqlite.execute(`
create table if not exists favorite_song_searches (
id integer primary key autoincrement,
artist text not null,
title text not null,
track_id text,
is_hidden BOOLEAN default FALSE,
UNIQUE(artist, title)
)
`);
const db = drizzle(sqlite as any);
const favoriteSongSearches = sqliteTable("favorite_song_searches", {
id: integer("id").primaryKey(),
track_id: text("track_id").notNull(),
artist: text("artist"),
title: text("title"),
});
favorites.forEach(async (track) => {
await db.insert(favoriteSongSearches)
.values({ ...track })
.onConflictDoNothing();
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 28, 2024