FunnyORM.jl Documentation
Basics
FunnyORM.AbstractModel — Type
AbstractModel is the base type for your models. You should not instantiate your model manually.
You get it with a:
- query:
db[MyModel[conditions...]][idx] - insertion:
MyModel(db)(kwargs) - updating:
newmodel = db[oldmodel](update_kwargs...)or@update db[model] key1=val1 key2=val2 ...
FunnyORM.DB — Type
Wrapper around a connection and lookup from its catalog. See also AbstractModel, TableQuery
Querying
FunnyORM.TableQuery — Type
Allows for special query syntax and converts to an SQL Node when used in a query. It also hold the type information to convert the query output back into your defined model. You construct it like this:
julia> MyModel[(x=3, y=[4,6]), z=3:5, date=""=>"2022-02-22", RelatedModel[name="%aa_bb%"]]
FunnyORM.TableQuery{MyModel}(...)Pass it to DB:
julia> db[MyModel[]]
Vector{MyModel}...Updating
FunnyORM.@update — Macro
Usage @update db[itemtoupdate] key1=val1 key2=val2 ..
Examples
julia> firstperson = first(db[Person[]]); firstperson.year_of_birth
1940
julia> @update db[firstperson] year_of_birth=1941; firstperson.year_of_birth
1941Base.getindex — Method
db[oldmodel](update_kwargs...) returns an updated model.
db[model]() will not run the update query, so db[model] is a closure to return the up-to-date model when called.
Examples
julia> firstperson = first(db[Person[]]); firstperson.year_of_birth
1940
julia> updated = db[firstperson](year_of_birth=1941); firstperson.year_of_birth, updated.year_of_birth
(1940, 1941)