Api
StructDatabaseMapping.select_one
— Functionfunction select_one(mapper::DBMapper, T::Type{<:Model}; kwargs...)
Select one element from the database
Arguments
mapper::DBMapper
: The database mapperT::DataType
: Datatype of a registered model we want to selectkwargs
: fields we want to search for. The param pk cand be used as generic way
to identify the primary key of the struct
struct Author <: Model ... end
select_one(mapper, Author, name="Borges")
StructDatabaseMapping.select_all
— Functionselect_all(mapper::DBMapper, T::Type{<:Model}; ; fields::Array{Symbol}=[], kwargs...)
Select all the elements that meet a criteria
Arguments
mapper::DBMapper
: The database mapperT::DataType
: Datatype of a registered model we want to search forkwargs
: criteria we want to search
struct Author <: Model ... end
select_all(mapper, Author, age=30)
StructDatabaseMapping.update!
— Functionfunction update!(mapper::DBMapper, elem::T; fields::Array{Symbol}=Symbol[]) where T<:Model
Insert the element in the database
Arguments
mapper::DBMapper
: The database mapperelem::T where T<:Model
: Instantied model to insertfields::Array{Symbol}
: Optional. Array of fields to update.
struct Author <: Model ... end
author = Author(name="some name", age=30)
update!(mapper, author)
update!(mapper, author, fields=[:age])
function insert!(mapper::DBMapper, dbtype::Type{Relational}, elem::T) where T
Insert the element in the database. Update the id of the element
Base.delete!
— Functionfunction delete!(mapper::DBMapper, T::Type{<:Model}; kwargs...)
Remove elements from the database
Arguments
mapper::DBMapper
: The database mapperT::DataType
: Datatype of a registered model we want to deletekwargs
: fields we want to search for existence.
struct Author <: Model ... end
delete!(mapper, Author, name="some name", age=30)
function delete!(mapper::DBMapper, T::Type{<:Model}; kwargs...)
Remove elements from the database
Arguments
mapper::DBMapper
: The database mapperelem<:Model
: Element to delete
The element needs a valid identifier.
struct Author <: Model ... end
delete!(mapper, Author(id=valid_id, name="some name", age=30))
StructDatabaseMapping.drop_table!
— Functionfunction drop_table!(mapper::DBMapper, T::DataType)
Eliminates (when possible) the struct data from the DB
Arguments
mapper::DBMapper
: The database mapperT::Type{<:Model}
: Datatype of a registered model
StructDatabaseMapping.clean_table!
— Functionclean_table!(mapper::DBMapper, T::Type{<:Model})
Remove all elements of the type T.
Arguments
mapper::DBMapper
: The database mapperT::Type{<:Model}
: Datatype of a registered model
In cases when possible the structure where those elements are stored (tables in relational case)
StructDatabaseMapping.exists
— Functionfunction exists(mapper::DBMapper, T::Type{T}; kwargs...) where T <: Model
Return wether the element exists in the database
Arguments
mapper::DBMapper
: The database mapperT::DataType
: Datatype of a registered model we want to know their existencekwargs
: fields we want to search for existence. The param pk cand be used as generic way
to identify the primary key of the struct
struct Author <: Model ... end
exists(mapper, Author, name="some name", age=30)
function exists(mapper::DBMapper, elem::T) where T<:Model
Return wether the element exists in the database
Arguments
mapper::DBMapper
: The database mapperelem<:Model
: Element to determine its existence
struct Author <: Model ... end
exists(mapper, Author(name="some name", age=30))