Genie Discord forum
There is a demo app that creates music albums. One feature add that I need to understand is adding the list of songs in the album database. There might be 7-12 songs in an album for example.
How to set up the table?
import SearchLight: AbstractModel, DbId import Base: @kwdef
@kwdef mutable struct Albums <: AbstractModel id::DbId = DbId() title::String = "" authors::String = "" year::Int = 0 songs::??? #how to make this a list? end
It is not possible to directly store an array to the DB. You could add a new table for the songs, where each song has an album id. Then, to retrieve all of the songs in an album you'd call something like
SearchLight.find(Song, SQLWhereExpression("album_id = $albumid"))
we will work on searchlight this summer for sure. We need to support complex db operations
another way to do it is to JSON-encode the list into a
noting that SQLite does not support native array columns at all.
but all 3 supported DB providers do support JSON stuff in their SQL implementation, so you'd still be able to write queries against the column