Initial WIP data models, fiber_orm mappings.
This commit is contained in:
parent
85f37373b6
commit
bbd7952232
27
src/main/nim/wdiwtlt/db.nim
Normal file
27
src/main/nim/wdiwtlt/db.nim
Normal file
@ -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])
|
9
src/main/nim/wdiwtlt/medialibrary.nim
Normal file
9
src/main/nim/wdiwtlt/medialibrary.nim
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import std/[paths]
|
||||||
|
import namespaced_logging
|
||||||
|
|
||||||
|
import ./[db, models]
|
||||||
|
|
||||||
|
type
|
||||||
|
MediaLibrary* = ref object
|
||||||
|
db: WdiwtltDb
|
||||||
|
libraryRoot: Path
|
56
src/main/nim/wdiwtlt/models.nim
Normal file
56
src/main/nim/wdiwtlt/models.nim
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user