this repo has no description
0
fork

Configure Feed

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

working on db

+55 -12
+2 -2
justfile
··· 1 1 2 2 3 3 migrate: 4 - odin run ./src/db/migrate.odin -file 4 + odin run ./src/db/migrate.odin -file -- oudio.db 5 5 6 6 drop: 7 - rm -rf ./oudio.db 7 + rm -rf oudio.db
+33 -8
src/db/main.odin
··· 1 1 package db 2 2 3 + import "core:fmt" 4 + import "core:strings" 3 5 4 6 import sqlite "../../vendor/sqlite" 5 7 import sa "../../vendor/sqlite/addons" 6 8 import t "../core" 9 + import "core:encoding/uuid" 10 + 11 + gen_id :: proc(prefix: Maybe(string), allocator := context.allocator) -> string { 12 + id: string 13 + 14 + id_uuid := uuid.generate_v7_basic() 15 + 16 + if (prefix != nil) { 17 + id = strings.concatenate([]string{prefix.?, "_", uuid.to_string(id_uuid, allocator)}) 18 + } else { 19 + id = uuid.to_string(id_uuid, allocator) 20 + } 21 + 22 + return id 23 + } 24 + 25 + new_album :: proc(db: ^sqlite.Connection, album: t.Album) -> sqlite.Result_Code { 26 + 27 + id := gen_id("album") 7 28 8 - DB_URL :: "oudio.db" 29 + return sa.execute( 30 + db, 31 + "INSERT INTO album (id,title,mb_id,mb_rg_id) VALUES (?, ?, ?, ?)", 32 + {{1, id}, {2, album.title}, {3, album.mb_id.?}, {4, album.mb_rg_id.?}}, 33 + ) 34 + } 9 35 10 - new_album :: proc( 11 - db: ^sqlite.Connection, 12 - album: t.Album, 13 - allocator := context.allocator, 14 - ) -> sqlite.Result_Code { 36 + 37 + new_artist :: proc(db: ^sqlite.Connection, artist: t.Artist) -> sqlite.Result_Code { 38 + 39 + id := gen_id("artist") 15 40 16 41 return sa.execute( 17 42 db, 18 - "INSERT INTO album (id,title,mb_id,mb_rg_id) values (?,?,?,?)", 19 - {{1, "test"}, {2, album.title}, {3, album.mb_id.?}, {4, album.mb_rg_id.?}}, 43 + "INSERT INTO artist (id, name, mb_id, acoust_id) VALUES (?, ?, ?, ?)", 44 + {{1, id}, {2, artist.name}, {3, artist.mb_id.?}, {4, artist.acoust_id.?}}, 20 45 ) 21 46 }
+17 -1
src/db/migrate.odin
··· 12 12 13 13 main :: proc() { 14 14 15 + args := os.args 16 + fmt.printfln("Args: |%#v|", args) 17 + 18 + db_url: cstring = "db.sqlite" 19 + 20 + if len(args) == 2 { 21 + last := args[1] 22 + 23 + if (len(last) > 0 && 24 + (strings.has_suffix(last, ".db") || strings.has_suffix(last, ".sqlite"))) { 25 + 26 + db_url = strings.clone_to_cstring(last) 27 + } 28 + } 29 + 30 + 15 31 track: mem.Tracking_Allocator 16 32 mem.tracking_allocator_init(&track, context.allocator) 17 33 context.allocator = mem.tracking_allocator(&track) ··· 58 74 59 75 db: ^sqlite.Connection 60 76 61 - if rc := sqlite.open(DB_URL, &db); rc != .Ok { 77 + if rc := sqlite.open(db_url, &db); rc != .Ok { 62 78 fmt.panicf("failed to open database. result code {}", rc) 63 79 } 64 80 fmt.printfln("connected to database")
+3 -1
src/db/migrations/01-init.sql
··· 13 13 14 14 CREATE TABLE artist ( 15 15 id TEXT PRIMARY KEY, 16 - name TEXT NOT NULL UNIQUE 16 + name TEXT NOT NULL UNIQUE, 17 + mb_id TEXT, 18 + acoust_id TEXT 17 19 ); 18 20 19 21 CREATE TABLE track (