diff --git a/src/main/nim/wdiwtlt/db.nim b/src/main/nim/wdiwtlt/db.nim new file mode 100644 index 0000000..6703d74 --- /dev/null +++ b/src/main/nim/wdiwtlt/db.nim @@ -0,0 +1,27 @@ +import std/[json, jsonutils, options, sequtils, strutils, times] +import db_connector/db_sqlite +import waterpark/sqlite +import fiber_orm, namespaced_logging, timeutils + +import ./models + +export fiber_orm.NotFoundError +export fiber_orm.PaginationParams +export fiber_orm.PagedRecords +export fiber_orm.enableDbLogging +export sqlite.close + +type + WdiwtltDb* = SqlitePool + + +func toJsonHook*(dt: DateTime): JsonNode = %(dt.formatIso8601) +proc fromJsonHook*(dt: var DateTime, n: JsonNode): void = + dt = n.getStr.parseIso8601 + + +proc initDB*(dbPath: string): SqlitePool = + newSqlitePool(10, dbPath) + +generateProcsForModels(WdiwtltDb, + [Artist, Album, MediaFile, Tag, Playlist, Bookmark, Image]) diff --git a/src/main/nim/wdiwtlt/medialibrary.nim b/src/main/nim/wdiwtlt/medialibrary.nim new file mode 100644 index 0000000..9cebb52 --- /dev/null +++ b/src/main/nim/wdiwtlt/medialibrary.nim @@ -0,0 +1,9 @@ +import std/[paths] +import namespaced_logging + +import ./[db, models] + +type + MediaLibrary* = ref object + db: WdiwtltDb + libraryRoot: Path diff --git a/src/main/nim/wdiwtlt/models.nim b/src/main/nim/wdiwtlt/models.nim new file mode 100644 index 0000000..510f86b --- /dev/null +++ b/src/main/nim/wdiwtlt/models.nim @@ -0,0 +1,56 @@ +import std/[options, paths, times] +import uuids + +type + Artist* = object + id*: UUID + name*: string + + Album* = object + id*: UUID + name*: string + year*: Option[int] + trackTotal*: int + + MediaFile* = object + id*: UUID + name*: string + discNumber*: int + trackNumber*: Option[int] + playCount*: int + filePath*: Path + fileHash*: string + metaInfoSource*: string + dateAdded*: DateTime + lastPlayed*: Option[DateTime] + presentLocally*: bool + comment*: string + + Tag* = object + id*: UUID + name*: string + description*: string + + Playlist* = object + id*: UUID + userCreated*: bool + name*: string + mediaFileCount*: int + copiedFromId*: Option[UUID] + createdAt*: DateTime + lastUsedAt*: DateTime + + Bookmark* = object + id*: UUID + name*: Option[string] + userCreated*: bool + playlistId*: UUID + mediaFileId*: UUID + playIndex*: int + playTimeMs*: int + createdAt*: DateTime + lastUsedAt*: DateTime + + Image* = object + id*: UUID + url*: string