Api

StructDatabaseMapping.select_oneFunction
function select_one(mapper::DBMapper, T::Type{<:Model}; kwargs...)

Select one element from the database

Arguments

  • mapper::DBMapper: The database mapper
  • T::DataType: Datatype of a registered model we want to select
  • kwargs: 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")       
source
StructDatabaseMapping.select_allFunction
select_all(mapper::DBMapper, T::Type{<:Model}; ; fields::Array{Symbol}=[], kwargs...)

Select all the elements that meet a criteria

Arguments

  • mapper::DBMapper: The database mapper
  • T::DataType: Datatype of a registered model we want to search for
  • kwargs: criteria we want to search
struct Author <: Model ... end
select_all(mapper, Author, age=30)
source
StructDatabaseMapping.update!Function
function update!(mapper::DBMapper, elem::T; fields::Array{Symbol}=Symbol[]) where T<:Model

Insert the element in the database

Arguments

  • mapper::DBMapper: The database mapper
  • elem::T where T<:Model: Instantied model to insert
  • fields::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])       
source
function insert!(mapper::DBMapper, dbtype::Type{Relational}, elem::T) where T

Insert the element in the database. Update the id of the element

source
Base.delete!Function
function delete!(mapper::DBMapper, T::Type{<:Model}; kwargs...)

Remove elements from the database

Arguments

  • mapper::DBMapper: The database mapper
  • T::DataType: Datatype of a registered model we want to delete
  • kwargs: fields we want to search for existence.
struct Author <: Model ... end
delete!(mapper, Author, name="some name", age=30)
source
function delete!(mapper::DBMapper, T::Type{<:Model}; kwargs...)

Remove elements from the database

Arguments

  • mapper::DBMapper: The database mapper
  • elem<: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))
source
StructDatabaseMapping.drop_table!Function
function drop_table!(mapper::DBMapper, T::DataType)

Eliminates (when possible) the struct data from the DB

Arguments

  • mapper::DBMapper: The database mapper
  • T::Type{<:Model}: Datatype of a registered model
source
StructDatabaseMapping.clean_table!Function
clean_table!(mapper::DBMapper, T::Type{<:Model})

Remove all elements of the type T.

Arguments

  • mapper::DBMapper: The database mapper
  • T::Type{<:Model}: Datatype of a registered model

In cases when possible the structure where those elements are stored (tables in relational case)

source
StructDatabaseMapping.existsFunction

function exists(mapper::DBMapper, T::Type{T}; kwargs...) where T <: Model

Return wether the element exists in the database

Arguments

  • mapper::DBMapper: The database mapper
  • T::DataType: Datatype of a registered model we want to know their existence
  • kwargs: 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)
source
function exists(mapper::DBMapper, elem::T) where T<:Model

Return wether the element exists in the database

Arguments

  • mapper::DBMapper: The database mapper
  • elem<:Model: Element to determine its existence
struct Author <: Model ... end
exists(mapper, Author(name="some name", age=30))
source