Database wrapper and ORM for Crystal, inspired by Ecto

Releases:

  • v0.10.1 - November 4, 2018
  • v0.10.0 - October 25, 2018
  • v0.9.0 - June 20, 2018
  • v0.8.6 - May 28, 2018
  • v0.8.5 - April 16, 2018

Dependencies:

Owner:

Crecto

crecto

https://www.crecto.com/

Build Status Join the chat at https://gitter.im/crecto/Lobby

Robust database wrapper for Crystal. Inspired by Ecto for Elixir language.

With built in query composer, associations, transactions, validations, constraints, and more.

Website with guides and examples - https://www.crecto.com/

See api docs - http://docs.crecto.com

Example

user = User.new
user.name = "Shakira"

changeset = Repo.insert(user)
changeset.errors.any?

inserted_user = changeset.instance
inserted_user.name = "Keanu"

changeset = Repo.update(user)
changeset.errors.any?

updated_user = changeset.instance

changeset = Repo.delete(updated_user)

Usage and Guides

Visit www.crecto.com

Benchmarks

Support

Buy Me A Coffee

Contributing

  1. Fork it ( https://github.com/fridgerator/crecto/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Development Notes

When developing against crecto, the database must exist prior to testing. There are migrations for each database type in spec/migrations, and references on how to migrate then in the .travis.yml file.

Create a new file spec/repo.cr and create a module name Repo to use for testing. There are example repos for each database type in the spec folder: travis_pg_repo.cr, travis_mysql_repo.cr, and travis_sqlite_repo.cr

When submitting a pull request, please test against all 3 databases.

Thanks / Inspiration

Crecto Change Log

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

0.10.0 2018-10-25

  • Updated to crystal 0.26.1
  • Allow defining models without any fields - @jreinert
  • Queries in preloads
  • Live transactions with Repo#transaction! - @jreinert
  • Changed model to use JSON::Serializable - @jreinert
  • Fields now correctly compare nil - @shiba-hiro
  • Added Repo#join method override with string argument - @shiba-hiro
  • Added more where and or_where method signatures - @jreinert
  • Added int8 and int16 suppoert - @jianghengle
  • Improved performance using String::Builder to build query strings - @jreinert
  • Added Repo#get_by method overloads to use Query objects - @jreinert
  • Compiler improvements by only including associations when used - @jianghengle
  • Updated to use new crystal time / timezone format - @wontruefree
  • Handle single-column updates for postgres 10.x - @faultyserver
  • Added Schema#cast and Schema#cast! mass assignment methods - @jreinert
  • Fixed has_one preloads - @jreinert

0.9.0 2018-06-18

  • Added Crecto logo thanks to @faustinoaq
  • Updated for crystal 0.25.0

0.8.6 2018-05-28

  • Fixed unique constraint on primary key fields
  • Fixed inserts of records with no primary key
  • README updates @jwoertink
  • Added more benchmarks
  • Moved to guide on gitbook, updated to simple readme

0.8.5 2018-04-16

  • Refactor types and transactions @jreinert
  • Added some benchmarks vs crystal-db
  • Added String to PkeyValue to allow for string primary keys in joins @jwoertink
  • Allow updating PkeyValue from has @helaan

0.8.4 2018-01-31

  • Added support for crystal Logger
  • Fixed Logger support @grig191
  • Added type cast (non nilable) attributes @jianghengle

0.8.3 2018-01-14

  • Updated for Crystal 0.24.1

0.8.2 2017-12-15

  • Cleaned up README @faustinoaq
  • Fixed join on belogns_to associations
  • Enabled logging on aggregate queries

0.8.1 2017-11-20

  • changeset validations now validate virtual attibutes

0.8.0 2017-11-11

  • added default option to fields to set a default value
  • added raw_query, raw_exec, and raw_scalar to Repo to run queries directly on adapter connection
  • added support for postgres array types

0.7.1 2017-10-22

  • fixed bug introduced in 0.7.0 for users not using postgres

0.7.0 2017-10-19

  • renamed constants with CRECTO_ prefix to prevent collisions with other libraries
  • fixed @crecto_db instance variable in repo config @vladfaust
  • added missing repo config options to the query string
  • added single quote around primary key fields in queries
  • patched a delete and delete_all query connection leak
  • Added unique_constraint

0.6.2 2017-7-30

  • fixed bug when using model classes like Module::Class
  • handle Json type in update_from_hash
  • added more types to inclusion / exclusion validators

0.6.1 2017-07-14

  • Crystal 0.23.1 support
  • fix WHERE IN query with empty Array @metacortex
  • (breaking change) created_at_field changed to set_created_at_field, updated_at_field changed to set_updated_at_field
  • option to use schema without a primary key
  • use 'first?' to prevent 'IndexError' when insert/update @metacortex

0.6.0 2017-05-26

  • enum_field support for Enums as model fields @faultyserver
  • update_from_hash method added, for updating records from HTTP::Params#to_s (to support crecto-admin)
  • (breaking change) added Repo#get_association, depreciating Repo#get(post, :user) and Repo#all(user, :posts) for getting associations
  • Fix Repo.get for associations @faultyserver
  • Always set has_many association values @faultyserver

0.5.4 2017-05-20

  • Moved Crecto to an organization
  • unique parameters in WHERE IN query
  • fix bug in Query.where, cast params to DbValue @faultyserver
  • Separate nilable/non-nilable accessors for associations @faultyserver
  • Repo#all preloads from opts now
  • fixed Repo#get! with a Query, was previously breaking

0.5.3 2017-04-23

  • bump crystal db version for crystal 0.22.0

0.5.2 2017-04-18

  • critical bug preventing database connection from being pooled

0.5.1 2017-04-13

  • fixed Repo - timezone issue @metacortex
  • SMALLINT support (postgres and mysql)
  • can use String type as primary key

0.5.0 2017-04-04

  • fixed but preventing updating of nil or false values - @Zhomart
  • (breaking change) changed usage of Repo. Repo is now user defined and is where database configuration is set.
  • dependent options: dependent: :delete, dependent: :nullify
  • added repo.confi uri option for faster configuration or configuring through a single ENV variable

0.4.4 2017-03-24

  • force all Int type fields to PkeyValue
  • Sqlite3 adapter - @Zhomart

0.4.3 2017-03-21

  • update to crystal-db 0.4.0

0.4.2 2017-03-21

  • added validate_length with array parameter @metacortex
  • supports IS NULL in .where query - .where(name: nil)
  • schema refactor
  • (breaking change) added #get! and #get_by to Repo. #get and #get_by will return nil if no record exists (nilable), where #get! and #get_by will raise an errorif no record exists (not nilable)
  • using belongs_to association will auto set the foreign key (belongs_to :user, User will assume field :user_id, PkeyValue)

0.4.1 2017-03-14

  • BaseAdapter database adapters refactor
  • #distinct queries
  • 'Json' field type (postgres only)
  • Database logging
  • travis runs postgres AND mysql specs / adapter query specs @neovintage
  • Fix to support unstrict schema mapping (#41) @huacnlee
  • Fix empty preloads @huacnlee

0.4.0 2017-02-26

  • Repo.get now raises NoResults error if no record is found
  • MULTI + TRANSACTIONS!

0.3.5 2017-02-21

  • Repo#aggregate methods
  • has_one relation type
  • added explicit require "json"
  • update_all method override to allow for named tuples

0.3.4 2017-01-06

  • fixed has_many through preloads when join association doesn’t exist
  • include JSON.mapping in schema

0.3.3 2016-12-31

  • close DB::ResultSet after usage (to free pool)

0.3.1 2016-12-28

  • Mysql Adapter
  • moved association preload to Query instead of Repo.all option
  • joins queries and has_many through associations

0.3.0 2016-12-17

  • Check for result.rows.size in queries - @neovintage
  • or_where queries
  • update_all queries
  • delete_all queries
  • raw (aribtrary) sql queries (i.e. Crecto::Repo.query("select * from users")) - @neovintage
  • now using crystal-db
  • has_many associations, with preload
  • belongs_to assocaitions

0.2.0 2016-11-30

  • Added this changelog
  • Paramterized queries to prevent SQL Injection
  • Generic / proc validations - @neovintage
  • ActiveRecord style validations - @cjgajard
  • BIGINT support - @neovintage

0.1.0

  • Schema
  • Repo
  • Changeset
  • Query
  • Postgres Adapter
Github statistic:
  • 280
  • 36
  • 13
  • 21
  • about 7 hours ago

License:

MIT License

Links: