-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NULL in database triggers UndefRefError #24
Comments
Oof, forgot to change Book(;
id = DbId(),
title = "",
author = "",
cover = ""
) = new("books", "id", id, title, author) to include the cover in the Pretty hard to find this based on the error message alone, though. Would be cool if some way of reducing potential for this error could be implemented. (Maybe suggest using |
@CarpeNecopinum Thanks, happy to take a look as I'm revamping SearchLight, but can you instruct how to reproduce? |
Ah, I understand, one of the fields is not added to the model, but it's added to the table... Interesting, I'll test. |
I was missing the |
I tested using Base: @kwdef
@kwdef mutable struct Book <: AbstractModel
### INTERNALS
_table_name::String = "books"
_id::String = "id"
### FIELDS
id::DbId = DbId()
title::String = ""
author::String = ""
cover::String = ""
end That way one's less likely to write a broken constructor for your models. |
Sounds great! The "internal" fields will be gone in a few days as I'm refactoring to the idiomatic Julia way. So we'll just specialise methods as in # in Books.jl
function SearchLight.table_name(b::Book) And probably have a default # in SearchLight.jl
function table_name(m::T) where {T<:AbstractModel}
# logic for default table name, ie return "books" from `Book`
end This approach should considerably simplify the API and cleanup the code. |
Yes, |
@CarpeNecopinum Some early experiments, this looks great! module Cars
using SearchLight
import Base: @kwdef
export Car
@kwdef mutable struct Car <: AbstractModel
id::DbId = DbId()
make::String = ""
max_speed::Int = 220
end
SearchLight.table_name()::String = "cars" # name of the DB table
SearchLight.pk()::String = "id" # name of the table's primary key
end |
Shouldn't it be more like But yeah, I really like the idea of moving the table name and key column away from the model instances. Makes things much cleaner. |
Yes, my bad, it takes the model as the argument! 😁 |
Playing through the Genie "Bill Gates Books" tutorial. The migration to the second version of the DB (i.e. adding the
cover
column) breaks SearchLight:Appears whenever
all(Book)
is ran.This appears to be due to handling of missing values. Opening the database in SQLite.jl the
cover
column in particular is typed asUnion{Missing,String}
. So I assume the problem springs from trying to turn aMissing
into aString
as required by theBook
model struct.Changing the type of
cover
toUnion{Missing,String}
leads to the same error.The text was updated successfully, but these errors were encountered: