WIP. A little custom music server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: drizzle relations

+69 -5
+2 -2
api-testing/get-album-by-id.bru
··· 5 5 } 6 6 7 7 get { 8 - url: http://localhost:3003/album/:id 8 + url: http://localhost:3003/album2/:id 9 9 body: none 10 10 auth: inherit 11 11 } 12 12 13 13 params:path { 14 - id: 01994d9b-0c5c-7003-862e-ad9a8de164df 14 + id: 019989a6-4774-7004-a3e8-f349e5896c98 15 15 } 16 16 17 17 settings {
+21
backend/src/api.ts
··· 28 28 ApiService, 29 29 { 30 30 readonly getAlbumList: () => Effect.Effect<AlbumWithArtist[], SqlError.SqlError, DatabaseLive>; 31 + readonly getAlbum2: (id: string) => Effect.Effect<any, SqlError.SqlError | AlbumNotFoundError, DatabaseLive>; 31 32 readonly getAlbum: ( 32 33 id: string, 33 34 ) => Effect.Effect<GetAlbum, SqlError.SqlError | AlbumNotFoundError, DatabaseLive>; ··· 40 41 const db = yield* DatabaseLive; 41 42 42 43 return { 44 + getAlbum2: (id: string) => 45 + Effect.gen(function* () { 46 + const rows = yield* db.query.albumTable.findMany({ 47 + //where: eq(albumTable.id, id), 48 + 49 + with: { 50 + songs: true, 51 + }, 52 + }); 53 + 54 + return rows; 55 + }), 43 56 getAlbum: (id: string) => 44 57 Effect.gen(function* () { 45 58 const rows = yield* db ··· 134 147 pipe( 135 148 ApiService, 136 149 Effect.andThen((x) => x.getAlbumList()), 150 + runtime.runPromise, 151 + ), 152 + ) 153 + 154 + .get("/album2/:id", ({ params: { id } }) => 155 + pipe( 156 + ApiService, 157 + Effect.andThen((x) => x.getAlbum2(id)), 137 158 runtime.runPromise, 138 159 ), 139 160 )
+46 -3
backend/src/db/schema.ts
··· 22 22 .references(() => albumTable.id, { onDelete: "cascade" }), 23 23 }); 24 24 25 - export const fileToSongRelation = relations(songTable, ({ one }) => ({ 26 - file: one(fileTable), 25 + export const fileRelations = relations(fileTable, ({ one }) => ({ 26 + song: one(songTable, { 27 + fields: [fileTable.id], 28 + references: [songTable.fileId], 29 + }), 30 + })); 31 + 32 + export const songRelations = relations(songTable, ({ one, many }) => ({ 33 + file: one(fileTable, { 34 + fields: [songTable.fileId], 35 + references: [fileTable.id], 36 + }), 37 + album: one(albumTable, { 38 + fields: [songTable.albumId], 39 + references: [albumTable.id], 40 + }), 41 + artists: many(songToArtistTable), 27 42 })); 28 43 29 44 export const artistTable = sqliteTable( ··· 44 59 (t) => [unique().on(t.title)], 45 60 ); 46 61 47 - export const albumToSongRelation = relations(albumTable, ({ one, many }) => ({ 62 + export const artistRelations = relations(artistTable, ({ many }) => ({ 63 + songs: many(songToArtistTable), 64 + albums: many(artistToAlbumTable), 65 + })); 66 + 67 + export const albumRelations = relations(albumTable, ({ many }) => ({ 48 68 songs: many(songTable), 69 + artists: many(artistToAlbumTable), 49 70 })); 50 71 51 72 export const songToArtistTable = sqliteTable( ··· 73 94 }, 74 95 (t) => [unique().on(t.artistId, t.albumId)], 75 96 ); 97 + 98 + export const songToArtistRelations = relations(songToArtistTable, ({ one }) => ({ 99 + song: one(songTable, { 100 + fields: [songToArtistTable.songId], 101 + references: [songTable.id], 102 + }), 103 + artist: one(artistTable, { 104 + fields: [songToArtistTable.artistId], 105 + references: [artistTable.id], 106 + }), 107 + })); 108 + 109 + export const artistToAlbumRelations = relations(artistToAlbumTable, ({ one }) => ({ 110 + artist: one(artistTable, { 111 + fields: [artistToAlbumTable.artistId], 112 + references: [artistTable.id], 113 + }), 114 + album: one(albumTable, { 115 + fields: [artistToAlbumTable.albumId], 116 + references: [albumTable.id], 117 + }), 118 + }));