Skip to content

Commit

Permalink
v0.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Dec 4, 2019
1 parent 82efb59 commit 75da317
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 221 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.15.3 - 2019-12-04

* performance optimisations

## v0.15.2 - 2019-12-04

* added support for `options` in the db connection data - this is passed to the database adapter
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SearchLight"
uuid = "340e8cb6-72eb-11e8-37ce-c97ebeb32050"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.15.2"
version = "0.15.3"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
64 changes: 35 additions & 29 deletions src/Database.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ julia> Database.connect(dict)
PostgreSQL.PostgresDatabaseHandle(Ptr{Nothing} @0x00007fbf3839f360,0x00000000,false)
```
"""
@inline function connect() #::DatabaseHandle
function connect() #::DatabaseHandle
connect(SearchLight.config.db_config_settings)
end


function connect(conn_settings::Dict)
isdefined(@__MODULE__, :DatabaseAdapter) || connect!(conn_settings)

Expand All @@ -61,7 +63,7 @@ function connect(conn_settings::Dict)
end


@inline function connect!(conn_settings::Dict)
function connect!(conn_settings::Dict)
SearchLight.config.db_config_settings["adapter"] = conn_settings["adapter"]
setup_adapter() && Database.connect(conn_settings) #::DatabaseHandle
end
Expand All @@ -70,10 +72,12 @@ end
"""
"""
@inline function disconnect(conn)
function disconnect(conn)
DatabaseAdapter.disconnect(conn)
end
@inline function disconnect()


function disconnect()
DatabaseAdapter.disconnect(CONNECTION)
end

Expand All @@ -85,10 +89,12 @@ end
Invokes the database adapter's create database method. If invoked without param, it defaults to the
database name defined in `config.db_config_settings`
"""
@inline function create_database() :: Bool
function create_database() :: Bool
create_database(SearchLight.config.db_config_settings["database"])
end
@inline function create_database(db_name::String)::Bool


function create_database(db_name::String)::Bool
DatabaseAdapter.create_database(db_name)
end

Expand All @@ -99,7 +105,7 @@ end
Invokes the database adapter's create migrations table method. If invoked without param, it defaults to the
database name defined in `config.db_migrations_table_name`
"""
@inline function create_migrations_table(table_name::String) :: Bool
function create_migrations_table(table_name::String) :: Bool
DatabaseAdapter.create_migrations_table(table_name)
end

Expand All @@ -109,17 +115,17 @@ end
Sets up the DB tables used by SearchLight.
"""
@inline function init() :: Bool
function init() :: Bool
DatabaseAdapter.create_migrations_table(SearchLight.config.db_migrations_table_name)
end


@inline function escape_column_name(c::String) :: String
function escape_column_name(c::String) :: String
DatabaseAdapter.escape_column_name(c, CONNECTION)
end


@inline function escape_value(v::T)::T where {T}
function escape_value(v::T)::T where {T}
result = try
DatabaseAdapter.escape_value(v, CONNECTION)
catch ex
Expand All @@ -130,7 +136,7 @@ end
end


@inline function table_columns(table_name::String) :: DataFrames.DataFrame
function table_columns(table_name::String) :: DataFrames.DataFrame
query(DatabaseAdapter.table_columns_sql(table_name), suppress_output = true)
end

Expand All @@ -153,7 +159,7 @@ julia> SearchLight.to_fetch_sql(Article, SQLQuery(limit = 5)) |> Database.query;
...
```
"""
@inline function query(sql::String; suppress_output::Bool = false, system_query::Bool = false) :: DataFrames.DataFrame
function query(sql::String; suppress_output::Bool = false, system_query::Bool = false) :: DataFrames.DataFrame
df::DataFrames.DataFrame = DatabaseAdapter.query(sql, (suppress_output || system_query), CONNECTION)
(! suppress_output && ! system_query && SearchLight.config.log_db) && @info(df)

Expand All @@ -164,7 +170,7 @@ end
"""
"""
@inline function to_find_sql(m::Type{T}, q::SearchLight.SQLQuery, joins::Union{Nothing,Vector{SearchLight.SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
function to_find_sql(m::Type{T}, q::SearchLight.SQLQuery, joins::Union{Nothing,Vector{SearchLight.SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
DatabaseAdapter.to_find_sql(m, q, joins)
end

Expand All @@ -174,47 +180,47 @@ const to_fetch_sql = to_find_sql
"""
"""
@inline function to_store_sql(m::T; conflict_strategy = :error)::String where {T<:SearchLight.AbstractModel}
function to_store_sql(m::T; conflict_strategy = :error)::String where {T<:SearchLight.AbstractModel}
DatabaseAdapter.to_store_sql(m, conflict_strategy = conflict_strategy)
end


"""
"""
@inline function delete_all(m::Type{T}; truncate::Bool = true, reset_sequence::Bool = true, cascade::Bool = false)::Nothing where {T<:SearchLight.AbstractModel}
function delete_all(m::Type{T}; truncate::Bool = true, reset_sequence::Bool = true, cascade::Bool = false)::Nothing where {T<:SearchLight.AbstractModel}
DatabaseAdapter.delete_all(m, truncate = truncate, reset_sequence = reset_sequence, cascade = cascade)
end


"""
"""
@inline function delete(m::T)::T where {T<:SearchLight.AbstractModel}
function delete(m::T)::T where {T<:SearchLight.AbstractModel}
DatabaseAdapter.delete(m)
end


"""
"""
@inline function count(m::Type{T}, q::SearchLight.SQLQuery = SearchLight.SQLQuery())::Int where {T<:SearchLight.AbstractModel}
function count(m::Type{T}, q::SearchLight.SQLQuery = SearchLight.SQLQuery())::Int where {T<:SearchLight.AbstractModel}
DatabaseAdapter.count(m, q)
end


"""
"""
@inline function update_query_part(m::T)::String where {T<:SearchLight.AbstractModel}
function update_query_part(m::T)::String where {T<:SearchLight.AbstractModel}
DatabaseAdapter.update_query_part(m)
end


"""
"""
@inline function to_select_part(m::Type{T}, cols::Vector{SearchLight.SQLColumn}, joins::Union{Nothing,Vector{SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
function to_select_part(m::Type{T}, cols::Vector{SearchLight.SQLColumn}, joins::Union{Nothing,Vector{SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
DatabaseAdapter.to_select_part(m, cols, joins)
end
"""
Expand Down Expand Up @@ -244,63 +250,63 @@ end
"""
"""
@inline function to_from_part(m::Type{T})::String where {T<:SearchLight.AbstractModel}
function to_from_part(m::Type{T})::String where {T<:SearchLight.AbstractModel}
DatabaseAdapter.to_from_part(m)
end


"""
"""
@inline function to_where_part(w::Vector{SearchLight.SQLWhereEntity})::String
function to_where_part(w::Vector{SearchLight.SQLWhereEntity})::String
DatabaseAdapter.to_where_part(w)
end


"""
"""
@inline function to_order_part(m::Type{T}, o::Vector{SearchLight.SQLOrder})::String where {T<:SearchLight.AbstractModel}
function to_order_part(m::Type{T}, o::Vector{SearchLight.SQLOrder})::String where {T<:SearchLight.AbstractModel}
DatabaseAdapter.to_order_part(m, o)
end


"""
"""
@inline function to_group_part(group::Vector{SearchLight.SQLColumn}) :: String
function to_group_part(group::Vector{SearchLight.SQLColumn}) :: String
DatabaseAdapter.to_group_part(group)
end


"""
"""
@inline function to_limit_part(limit::SearchLight.SQLLimit) :: String
function to_limit_part(limit::SearchLight.SQLLimit) :: String
DatabaseAdapter.to_limit_part(limit)
end


"""
"""
@inline function to_offset_part(offset::Int) :: String
function to_offset_part(offset::Int) :: String
DatabaseAdapter.to_offset_part(offset)
end


"""
"""
@inline function to_having_part(having::Vector{SearchLight.SQLHaving}) :: String
function to_having_part(having::Vector{SearchLight.SQLHaving}) :: String
DatabaseAdapter.to_having_part(having)
end


"""
"""
@inline function to_join_part(m::Type{T}, joins::Union{Nothing,Vector{SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
function to_join_part(m::Type{T}, joins::Union{Nothing,Vector{SQLJoin{N}}} = nothing)::String where {T<:SearchLight.AbstractModel, N<:Union{Nothing,SearchLight.AbstractModel}}
DatabaseAdapter.to_join_part(m, joins)
end

Expand Down Expand Up @@ -346,15 +352,15 @@ end
"""
"""
@inline function rand(m::Type{T}; limit = 1)::Vector{T} where {T<:SearchLight.AbstractModel}
function rand(m::Type{T}; limit = 1)::Vector{T} where {T<:SearchLight.AbstractModel}
DatabaseAdapter.rand(m, limit = limit)
end


"""
"""
@inline function index_name(table_name::Union{String,Symbol}, column_name::Union{String,Symbol}) :: String
function index_name(table_name::Union{String,Symbol}, column_name::Union{String,Symbol}) :: String
string(table_name) * "__" * "idx_" * string(column_name)
end

Expand Down
Loading

2 comments on commit 75da317

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/6253

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.3 -m "<description of version>" 75da317b0a845dd6b0efbd32324744dfa3221347
git push origin v0.15.3

Please sign in to comment.