Releases: imdrasil/jennifer.cr
Release 0.8.0
It has been a long time since previous release but expectation is worth it. 0.8.0 release brings a lot of new features such as:
- extended model mapping
- new properties to configure sql column name and autoincrementability of primary key
- opportunity to define mapping in modules and abstract super classes
Model.new
now respectsafter_initialize
callbacks- unify mapping for model and view
- extended querying functionality
- make SQL API more natural
- support of upsert operation
- add
CTE
Also a lot of bugs were fixed and performance enhancements were made.
API documentation is hugely increased so now almost all places are covered.
Changelog
General
- by default
db:migrate
task outputs information about executed migrations db:create
command doesn't fail if database already exists
QueryBuilder
- remove redundant
Criteria#similar
which is loaded withpostgres
adapter - add
Query#insert
andQuery#upsert
- add
ExpressionBuilder#values
andValues
to reference toVALUES
statement in upsert .find_by_sql
and.to_a
ofModelQuery(T)
useT.new
instead ofT.build
- add
CommonTableExpression
to present SQL CTE - rename
EagerLoading#with
to#with_relation
#last!
and#last
assigns old limit value back after request instead of additional#reverse_order
call- speed up
Query
allocation by making all query part containers nilable - add 2nd argument to
Query#union
setting union to beUNION ALL
- now
Query#with
presents API for registering common table expression - add
Query#merge
Query#where
yields expression builderQuery
's#join
,#right_join
,#left_join
and#lateral_join
yield expression builders of a main query and joined context- add next SQL functions:
count
,sum
,avg
,min
,max
,coalesce
andconcat_ws
sql functions round
function now accepts second optional argument specifying precisionFunction
's#operands_to_sql
and#operand_sql
now are publicFunction.define
macro acceptscomment
key to specify function class documentation commentFunction.define
macroarity
argument by default is0
(instead of-1
)- add
ExpressionBuilder#cast
- handle an empty array passed to
Criteria#in
- fix missing
LIMIT
in query generated by#first!
- fix result type of
Executables#exists?
query method toBool
(thanks @skloibi) - add
Executables#explain
Model
Base.new
now callsafter_initialize
hooks and supports STIBase.build
now is alias forBase.new
- properties passed to
Mapping.mapping
now is parsed before main mapping macro is executed #append_{{relation_name}}
methods ofRelationDefinition
now use.new
to build a related objectResource::Supportable
alias is removedResource.search_by_sql
is removed in favour ofResource.all.find_by_sql
- fix bug with ignoring of field converter by a STI child
- fix default constructor for STI child - now it is generated if parent model has only
type
field without default value - allow mapping option
column
that defines a custom column name that is mapped to this field (thank @skloibi) Base#table_name
is moved toResource
Mapping
module now can be included by another module with mapping definitionSTIMapping
now doesn't convert result set to hash and use same logic asMapping
- add
:auto
mapping option to specify whether primary key is autoincrementable
Validation
- change
Validations::Uniqueness
to consider field mappings when validating properties (thank @skloibi) - allow passing multiple fields to
.validates_uniqueness
to validate combination uniqueness (thank @skloibi)
View
- introduce
Mapping
instead ofExperimentalMapping
; new mapping heavily reuseModel::Mapping
- allow specification of property aliases via
column
option (cf. Model) (thank @skloibi) - mapping shares same functionality as
Model
's
Adapter
- remove
Base::ArgType
alias - add
Base#upsert
Postgres::Adapter#data_type_exists?
is renamed to#enum_exists?
- fix bug for dropping foreign key for
postgres
adapter - remove
TableBuilderBuilders
- nowMigration::Base
creates commands by its own - speed-up tables column count fetch at application start-up
- Fix result type of
#exists?
query method toBool
forBase
andPostgres
adapters (thanks @skloibi) - add
Base#explain
abstract method and implementations forMysql
andPostgres
Config
- add
verbose_migrations
to hide or show migration details duringdb:migrate
command invocation
SqlGenerator
- add
.insert_on_duplicate
and.values_expression
toBaseSQLGenerator
as abstract methods and implementations toPostgres
andMysql
- now
BaseSQLGenerator.from_clause
accepts 2 arguments (instead of 2..3) accepting table name as 2nd argument - add
BaseSQLGenerator.with_clause
which generates CTE - add
BaseSQLGenerator.explain
Migration
- add
Base#tinyint
(not all adapter support it) - change next
Base
instance method signature:#foreign_key_exists?(from_table, to_table = nil, column = nil, name : String? = nil)
#add_index(table_name : String | Symbol, field : Symbol, type : Symbol? = nil, name : String? = nil, length : Int32? = nil, order : Symbol? = nil)
(same forTableBuilder::CreateTable#index
andTableBuilder::ChangeTable#add_index
)#drop_index(table : String | Symbol, fields : Array(Symbol) = [] of Symbol, name : String? = nil)
(same forTableBuilder::ChangeTable#drop_index
)#drop_foreign_key(to_table : String | Symbol, column = nil, name = nil)
(same forTableBuilder::ChangeTable#drop_foreign_key
)
- add
TableBuilder::CreateTable#column
as alias toTableBuilder::CreateTable#field
- new signature of
TableBuilder::CreateTable#reference
-#reference(name, type : Symbol = :integer, options : Hash(Symbol, AAllowedTypes) = DB_OPTIONS.new)
Record
- for missing fields
BaseException
exception is raised instead ofKeyError
Release 0.7.1
Changelog
QueryBuilder
#pluck
,#update
,#db_results
,#results
.#each_result_set
and#find_in_batches
ofQuery
respects#none
(returns empty result if it has being called)- remove deprecated
QueryObject
constructor accepting array of options and#params
Model
- fix mapping issue when all
Generic
s are assumed as unions (#208)
Validation
- allow passing multiple fields to
.validates_uniqueness
to validate combination uniqueness
Adapter
Mysql::SchemaProcessor
now respectsfalse
as column default valuePostgres::SchemaProcessor
now respectsfalse
as column default value
Config
- introduce new configuration
pool_size
which setsmax_idle_pool_size = max_pool_size = initial_pool_size
to the given value; getter#pool_size
returns#max_pool_size
postgres
is no more default adapter
Migration
TableBuilder::Base::AllowedTypes
alias includesFloat64
andJSON::Any
Release 0.7.0
Overview
This release was hard and pretty long. As a result we've got a set of very important features (like polymorphic relations and complex query update mechanism). Also as a side effect bunch of side-shards were appeared to fill gaps in missing functionality (like form parsing).
Also you can find 3 sample application describing possible way of integrating web frameworks/libraries with Jennifer:
Changelog
General
- bump
sam
to"~> 0.3.0"
- add sam command
generate:model
to generate model and related migration - move all logic regarding file generating to
Jennifer::Generators
space - add
db:seed
task as a placeholder seeding task db:setup
now invokesdb:seed
afterdb:migrate
QueryBuilder
- add
#and
,#or
and#xor
shortcut methods toExpressionBuilder
Criteria#in
now acceptsSQLNode
as well- add
Statement
module with base abstract functionality needed for query string generating ExpressionBuilder#g
and#group
now has no argument type restrictionGrouping#condition
now can be ofStatement
typeQuery
includesStatement
Query#to_sql
now is#as_sql
,#select_args
-#sql_args
Condition
includesStatement
Executables#update
accepts block expectingHash(Symbol, Statement)
to be returnedExecutables#modify
is removed in favor of new#update
method accepting block- now
LogicOperator
is inherited fromSQLNode
#delete
andexists?
ofExecutables
do nothing when#do_nothing?
istrue
- add
Query#do_nothing?
- add
Query.null
which returnsQuery.new.none
Join
acceptsGrouping
forON
condition
Model
- remove
Base.build_params
,Base.parameter_converter
methods - remove
ParameterConverter
class - fix skipping generating default constructor by
Mapping.mapping
when at least one field has default value and all others are nilable stringified_type
option is removed from theCOLUMNS_METADATA
STIMapping#arguments_to_save
&STIMapping#arguments_to_insert
now respect field converterTranslation
model now is includeable module- all class methods of
Translation
are moved toTranslation::ClassMethods
which is automatically extended by target class usingincluded
macro #lookup_ancestors
and#human_attribute_name
methods ofTranslation
are addedErrors#base
now is type ofTranslation
instead ofBase
- add
Base#persisted?
- now attribute-specific rendering for
Resource#inspect
is generated by.mapping
- add polymorphic relation support for
has_one
,has_many
andbelongs_to
relations - add
:nodoc:
for almost all generated relation methods (except#association
) - add missing relation names for criterion in
Relation::Base
methods - add
Relation::IPolymorphicBelongsTo
,Relation::PolymorphicHasMany
andRelation::PolymorphicHasOne
@new_record
,@destroyed
,@errors
, changeset and relation attributes now is ignored byJSON::Serializable
- add
skip_validation
argument toAuthentication.with_authentication
macro to specify whether validation should be added - add generating predicate method
#{{attribute}}?
for boolean attribute - allow
Jennifer::Model::Base#attribute=
to accept not only defined type but alsoJennifer::DBAny
- rename
Base#update_attributes
toBase#set_attributes
Validation
- all validation macros now accept
:if
key; the value may be bothSymbol
name of a method to be called or expression - replace validation logic generated during a macro call with new validators usage:
Validations::Absence
,Validations::Acceptance
,Validations::Confirmation
,Validations::Exclusion
,Validations::Format
,Validations::Inclusion
,Validations::Length
,Validations::Numericality
,Validations::Presence
,Validations::Uniqueness
- remove
Jennifer::Validator
in favour ofJennifer::Valdiations::Validator
- all validators by default implement singleton pattern
- all validation macros are moved to
Jennifer::Validations::Macros
View
- now attribute-specific rendering for
Resource#inspect
is generated by.mapping
- add generating predicate method
#{{attribute}}?
for boolean attribute
Adapter
- fix output stream for postgres schema dump
- remove legacy postgres insert
- add
Adapter#foreign_key_exists?
- add
Mysql::SchameProcessor
- now
Base#schema_processor
is abstract - add
Postgres::SchemaProcessor#rename_table
SchemaProcessor
now is abstract class- all builder methods are moved from
SchemaProcessor
class toTableBuilderBuilders
module - fix syntax in
SchemaProcessor#drop_foreign_key
- all
_query
arguments inBase
methods are renamed toquery
Base.extract_arguments
is removed.delete
,.exists
and.count
ofBaseSQLGenerator
now returns stringPostgres.bulk_insert
is removedTransaction#with_connection
ensure to release connection- all sqlite3 related code are removed
Config
- fix
migration_failure_handler_method
property from being global - add new property
model_files_path
representing model directory (is used in a scope of model generating) - fix ignoring
skip_dumping_schema_sql
config
SqlGenerator
.select_clause
now doesn't invoke.from_clause
under the hood.lock_clause
adds whitespaces around lock statement automatically
Migration
- remove
Runner.generate
andRunner::MIGRATION_DATE_FORMAT
TableBuilder::CreateTable#reference
triggers#foreign_key
and acceptspolymorphic
bool argument presenting whether additional type column should be added; for polymorphic reference foreign key isn't added
Exceptions
- 'RecordNotFound' from
QueryBuilder::Query#first!
andQueryBuilder::Query#last!
includes detailed parsed query
0.6.2
This is an intermediate release before the breaking 0.7.0
.
Changelog
General
- add
:nodoc:
to all internal constants and generated methods (implementing standard ORM methods) from the macros
QueryBuilder
Query
isn't extended byIfrit
- add
OrderItem
to describe order direction - add
Criteria#order
,Criteria#asc
andCriteria#desc
to createOrderItem
- add
Condition#eql?
to compare with other condition orSQLNode
(returnsfalse
) - add
Criteria#eql?
,Grouping#eql?
,LogicOperator#eql?
- add
Query#order
andQuery#reorder
with acceptingOrderItem
- now
Query#order
with block to expect aOrderItem
- remove
CriteriaContainer
QueryObject
now is an abstract class- changed wording for the
ArgumentError
in#max
,#min
,#sum
,#avg
methods ofAggregation
to "Cannot be used with grouping" - change
Query#from(_from : String | Query)
signature toQuery#from(from : String | Query)
Model
#save
and#update
will returntrue
when is called on an object with no changed fields (all before callbacks are invoked)- next
Base
methods become abstract:.primary_auto_incrementable?
,.build_params
,#destroy
,#arguments_to_save
,#arguments_to_insert
Base#_extract_attributes
andBase#_sti_extract_attributes
become private- all callback invocation methods become protected
- next
Resource
methods become abstract:.primary
,.field_count
,.field_names
,.columns_tuple
,#to_h
,#to_str_h
Resource
isn't extended byIfrit
- regenerate
.build_params
for STI models Scoping.scope(Symbol,QueryObject)
now checks in runtime whetherT
ofJennifer::QueryBuilder::ModelQuery(T)
responds to method named after the scope
View
Base#_after_initialize_callback
becomes protectedBase#_extract_attributes
becomes private
Adapter
- fix custom port not used when accessing the Postgres database
Migration
TableBuilder::Base
isn't extended byIfrit
- rename
TableBuilder::ChangeTable#new_table_rename
getter to#new_table_name
- fix misuse of local variable in
TableBuilder::ChangeTable#rename_table
TableBuilder::ChangeTable#change_column
has next changes:old_name
argument renamed toname
new_name
argument is replaced with option inoptions
arguemnt hash- raise
ArgumentError
if bothtype
andoptions[:sql_type]
arenil
TableBuilder::ChangeTable#change_column
raisesArgumentError
if bothtype
andoptions[:sql_type]
arenil
TableBuilder::CreateTable#field
data_type
argument renamed totype
TableBuilder::CreateTable#timestamps
creates fields withnull: false
by defaultTableBuilder::CreateTable#add_index
is removed in favour of#index
.pending_versions
,.assert_outdated_pending_migrations
and.default_adapter
methods ofRunner
become privateRunner.config
is removed
0.6.1
Changelog
General
- adds
Time::Span
to supported types
QueryBuilder
- allows listing any
SQLNode
instance in SELECT clause (like raw sql or functions) - removes redundant
SQLNode#sql_args_count
- adds
SQLNode#filterable?
function which presents if node has filterable sql parameter - refactors
Condition#sql_arg
- adds
Function
base abstract class for defining custom sql functions - adds
lower
,upper
,current_timestamp
,current_date
,current_time
,now
,concat
,abs
,ceil
,floor
,round
- adds
Join#filterable?
andQuery#filterable?
- raise
AmbiguousSQL
when%
symbol is found in the raw SQL (except%s
)
Model
- replaces mapping option
numeric_converter
with newconverter
- adds
NumericToFloat64Converter
andJSONConverter
- now
#to_h
and#to_str_h
use field getter methods - remove
puts
fromJSONConverter#from_db
Adapter
- propagate native
DB::Error
instead of wrapping it intoBadQuery
- manually release a connection when an exception occurs under the transaction
Config
- set default
max_pool_size
to 1 and warn about danger of setting differentmax_pool_size
,max_idle_pool_size
andinitial_pool_size
Migration
- adds
Migration::TableBuilder::CreateForeignKey
&Migration::TableBuilder::DropForeignKey
- adds
Migration::Base#add_foreign_key
&Migration::Base#drop_foreign_key
- adds
Migration::TableBuilder::ChangeTable#add_foreign_key
&Migration::TableBuilder::ChangeTable#drop_foreign_key
Exceptions
- add
AmbiguousSQL
- is raised when forbidden%
symbol is used in the raw SQL
Closer to the Web
This release brings a lot of features that are useful for the web-based applications. Enjoy 😄 🎈 🎉
Changelog
General
- adds support of crystal
0.25.0
- removes
time_zone
dependency - removes requiring
"inflector/string"
- adds cloning to
Time::Location
&Time::Location::Zone
- removes
Ifrit.typed_hash
andIfrit.typed_array
usage - presents "mapping types" which allows reusing common type definition
- now
Primary32
andPrimary64
are mapping types (not aliases ofInt32
andInt64
) - removes
accord
dependency
QueryBuilder
- allows nested eager loading in
ModelQuery(T)#eager_load
andModelQuery(T)#include
- all query eager loading methods are extracted to separate module
QueryBuilder::EagerLoading
which is included inQueryBuilder::IModelQuery
Model
- introduces model virtual attributes
- adds
Mapping.build_params
andParameterConverter
class for convertingHash(String, String)
parameters to acceptable by model - allows to specify table prefix
- all relations are stored in
Base::RELATIONS
- fixes building of sti objects using parent class
- adds
Jennifer::Model::Authentication
module with authentication logic - fixes compile time issue with
IRelation
when app has no belongs-to relation defined - fixes bug with reading
Int64
primary key - adds
#inspect
- adds
numeric_converter
mapping option for numeric postgres field - introduces new
Jennifer::Model::Errors
class replacingAccord::ErrorList
which mimics analogic rails one a lot; - moves
Translation::human_error
method functionality to introducedErrors
instance level - now next
Resource
static methods are abstract:actual_table_field_count
,primary_field_name
,build
,all
,superclass
Resource#inspect
returns simplified version (only class name and object id)Resource.all
now is a macro method- fixes
Model::Transaltion.lookup_ancestors
from breaking at compilation time - now all built-in validations use attribute getter methods instead of variables
View
- removes
ExperimentalMapping#attributes_hash
,ExperimentalMapping.strict_mapping?
Config
local_time_zone
now is aTime::Location
- local time zone is loaded using
Time::Location.local
as default value
SqlGenerator
- replaces
\n
with whitespace character as query part separator
Migration
- now migration version is taken from file name timestamp
Jennifer::Migration::Base.migrations
returns a hash of version number => migration class instead of array of classes
0.5.1
Anniversary release (v0.5.0)
At the age of 1 🎉
This is an anniversary release - 1 year ago the very first commit has been made. A lot of work have been done and a lot of will be but for now this it is the most powerful ORM for crystal - with flexible query dsl, mapping declaration, callbacks, validation, internationalization, migrating mechanism, materialized and non materialized view
Changes
- all adapter-related logic have been decoupled - all adapters could be required at the same place (one step forward to multi-adapter application support)
- added internationalization support - now human model name, attribute name and error message are translated using
i18n
shard - added support of
time_zone
- any time object is converted from local time to UTC during storing it to the db and vise versa - added new validation macros
- made one step from Accord - introduced new validator class and implemented own validation methods
- added new callbacks - update, commit and rollback
More complite list of changes could be found in CHANGELOG.md file. Also documentation .md
files has got new information - check it out.
Have an awesome coding and happy Valentine's day ❤️
Update to crystal 0.24.1
- All macro methods were rewritten to new 0.24.1 crystal syntax
Adapter
- removed
Jennifer::Adapter::TICKS_PER_MICROSECOND
- fixes
Jennifer::Adapter::Mysql#table_column_count
bug
Model
- add
Primary32
andPrimary64
shortcuts for primary key mapping (view mapping respects this as well) - add
::create!
&::create
with splatted named tuple arguments - now relation retrieveness is updated for any superclass relations as well
- a relation will be retrieved from db for only persisted record
- move
Jennifer::Mode::build
method to%mapping
macro - allow retrieving and building sti records using base class
- fix
#reload
method for sti record - optimize building sti record from hash
QueryBuilder
- fix
Criteria#not
- add
Criteria#ilike
View
- introduce
View::Materialized
superclass for materialized views - add
COLUMNS_METADATA
constant - add
::columns_tuple
which retrnsCOLUMNS_METADATA
- remove
::children_classes
- make
after_initialize
callback respect inheritance - add
::adapter
Exceptions
- add
AbstractMethod
exception which represents expectation of overriding current method by parents (is usefull when method can't be real abstract one) - add
UnknownSTIType
0.4.2
SqlGenerator
- rename
#trancate
to#truncate
Migration
-
rename
TableBuilder::DropInde
toTableBuilder::DropIndex
-
remove printing out redundand execution information during db drop and create
-
remove
Migration::Base::TABLE_NAME
constant -
allow to pass
QueryBuilder::Query
as source to theCreateMaterializedView
(postgres only)
Model
-
move
Base#build
method witout arguments toMapping
module under the%mapping
-
added
validates_presence_of
validation macros -
fixed callback invokation from parent classes
-
add
allow_blank
key tovalidates_inclusion
,validates_exclusion
,validates_format
-
add
ValidationMessages
module which includes methods generating validation error messages -
add
Primary32
andPrimary64
shortcuts forInt32
andInt64
primary field declarations for model and view -
allow use nil usions instead of
null: true
named tuple option
QueryBuilder
-
#count
method is moved fromExecutables
module to theAggregations
one -
changed method signature of
#find_in_batches
-
add
#find_each
- works same way as#find_in_batches
but yields each record instead of array -
add
#ordered?
method toOrdering
module -
switch
Criteria#hash
to useobject_id
as seed -
add
Query#eql?
-
add
Query#clone
and all related methods -
add
Query#except
- creates clone except given clauses -
make
IModelQuery
class as new superclass ofModelQuery(T)
; move all methods no depending onT
to the new class