diff --git a/docs/index.json b/docs/index.json index eafee21..946c055 100644 --- a/docs/index.json +++ b/docs/index.json @@ -1 +1 @@ -{"repository_name":"dbx","body":"# :sparkles: DBX\n\n[![CI Status](https://github.com/Nicolab/crystal-dbx/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-dbx/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-dbx.svg)](https://github.com/Nicolab/crystal-dbx/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-dbx/)\n\n* DB connections manager\n* Query builder\n* ORM (alpha)\n\nDBX is a [Crystal lang](https://crystal-lang.org) module to query the database, built on top of [crystal-db](https://github.com/crystal-lang/crystal-db) (common API for DB drivers).\n\nDBX is designed in a decoupled way to embed only the necessary features (multi-connections manager, query builder, query executor and ORM).\n\n## Documentation\n\n* šŸš€ [Guide](/guide/README.md)\n* šŸ“˜ [API doc](https://nicolab.github.io/crystal-dbx/)\n* :bookmark_tabs: [Spec tests](https://github.com/Nicolab/crystal-dbx/tree/master/spec)\n\n## Contributing\n\n1. Fork it ().\n2. Create your feature branch (`git checkout -b my-new-feature`).\n3. See [Development](#Development).\n4. Commit your changes (`git commit -am 'Add some feature'`).\n5. Push to the branch (`git push origin my-new-feature`).\n6. Create a new Pull Request.\n\n### Development\n\n1. You only need Git, Docker and Docker-compose installed on your machine.\n2. Clone this repo and run `./scripts/prepare`.\n3. Run first `docker-compose up`,\n 1. then enter to container `docker-compose exec test_pg bash` (or `test_sqlite` service),\n 2. into the container `just dev-spec`.\n4. Check the project before committing or pushing, from the host: `./scripts/check`\n\nIt's just Docker and docker-compose, you can directly type all the commands Docker and docker-compose.\n\nāœØ Example:\n\n_Terminal 1_\n\n```sh\n# Start the dev stack\ndocker-compose up\n```\n\n_Terminal 2_\n\n```sh\n# enter in the test_pg container\ndocker-compose exec test_pg bash\n\n# then in the test_pg container\ncrystal run ./src/app.cr\n\n# or with a recipe (helper)\njust dev-spec # <= auto reload when the code change\n\n# recipe list\njust --list\n```\n\nAlso, quickly:\n\n* `docker-compose run --rm test_pg crystal spec`\n* or `docker-compose run --rm test_pg just dev-spec`\n* when you are done: `docker-compose down --remove-orphans`\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-dbx/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n* [Nicolas Talle (@Nicolab)](https://github.com/Nicolab) - Creator and maintainer.\n* Thanks to [@ilourt](https://github.com/ilourt) for the feedbacks and thoughts.\n* This project is useful to you? [Sponsor the developer](https://github.com/sponsors/Nicolab).\n","program":{"html_id":"dbx/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"dbx","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX","path":"DBX.html","kind":"module","full_name":"DBX","name":"DBX","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":60,"url":null},{"filename":"src/query_builder/builder.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":8,"url":null},{"filename":"src/query_builder/executor.cr","line_number":8,"url":null},{"filename":"src/query_builder/scope.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-dbx/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"DBX is a helper to handle multi DBs using the compatible drivers\nwith the common `crystal-db` module.\n\nExample with PostgreSQL:\n\n```\n# Connection URI / DSL https://www.postgresql.org/docs/current/libpq-connect.html#h5o-9\ndb = DBX.open(\"app\", \"postgres://...\", true)\n\npp DBX.db?(\"app\") ? \"defined\" : \"not defined\"\n\ndb.query \"select id, created_at, email from users\" do |rs|\n rs.each do\n id = rs.read(Int32)\n created_at = rs.read(Time)\n email = rs.read(String)\n puts \"##{id}: #{email} #{created_at}\"\n end\nend\n\n# Closes all connections of this DB connection pool and remove this DB connection pool.\nDBX.destroy(\"app\")\n```\n\nModel:\n\n```\nclass User\n include DBX::ORM::DSL\n\n field lang : String\n\n @[JSON::Field(key: \"firstName\")]\n field first_name : String?\nend\n\ndb = DBX.open \"app\", App.cfg.db_uri\n\nuser = User.from_rs(db.query(\"SELECT id, lang, first_name FROM users\"))\npp user.to_json\n\nuser = User.from_json \"{\\\"lang\\\":\\\"fr\\\",\\\"firstName\\\":\\\"Nico\\\"}\"\npp user\n```\n\nSee also `DBX::ORM` for a more advanced model system and query builder.\n\nResources:\n- https://crystal-lang.github.io/crystal-db/api/index.html\n- https://github.com/Nicolab/crystal-dbx/tree/master/guide","summary":"

DBX is a helper to handle multi DBs using the compatible drivers with the common crystal-db module.

","class_methods":[{"id":"db(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"db(name:String,uri:String,strict=false):DB::Database-class-method","name":"db","doc":"Same as `.open`.","summary":"

Same as .open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":92,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"self.open(name, uri, strict)"}},{"id":"db(name:String):DB::Database-class-method","html_id":"db(name:String):DB::Database-class-method","name":"db","doc":"Uses a given DB connection pool.","summary":"

Uses a given DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Database","args_html":"(name : String) : DB::Database","location":{"filename":"src/dbx.cr","line_number":87,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"@@dbs[name]"}},{"id":"db?(name:String):Bool-class-method","html_id":"db?(name:String):Bool-class-method","name":"db?","doc":"Checks that a DB connection pool exists.","summary":"

Checks that a DB connection pool exists.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Bool","args_html":"(name : String) : Bool","location":{"filename":"src/dbx.cr","line_number":82,"url":null},"def":{"name":"db?","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@@dbs.has_key?(name)"}},{"id":"dbs:DBHashType-class-method","html_id":"dbs:DBHashType-class-method","name":"dbs","doc":"Returns all `DB::Database` instances.","summary":"

Returns all DB::Database instances.

","abstract":false,"args":[],"args_string":" : DBHashType","args_html":" : DBHashType","location":{"filename":"src/dbx.cr","line_number":77,"url":null},"def":{"name":"dbs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBHashType","visibility":"Public","body":"@@dbs"}},{"id":"destroy(name:String)-class-method","html_id":"destroy(name:String)-class-method","name":"destroy","doc":"Closes all connections of the DB connection pool *name*\nand remove the *name* DB connection pool.","summary":"

Closes all connections of the DB connection pool name and remove the name DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String)","args_html":"(name : String)","location":{"filename":"src/dbx.cr","line_number":112,"url":null},"def":{"name":"destroy","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@dbs.has_key?(name)\n begin\n (self.db(name)).close\n rescue e : Exception\n puts(\"\\nšŸ‘» DBX.destroy: error caught when closing:\")\n pp(e)\n end\n @@dbs.delete(name)\nend"}},{"id":"destroy:Tuple(Int32,Int32)-class-method","html_id":"destroy:Tuple(Int32,Int32)-class-method","name":"destroy","doc":"Destroy all DB connection pool and and their connections.","summary":"

Destroy all DB connection pool and and their connections.

","abstract":false,"args":[],"args_string":" : Tuple(Int32, Int32)","args_html":" : Tuple(Int32, Int32)","location":{"filename":"src/dbx.cr","line_number":125,"url":null},"def":{"name":"destroy","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple(Int32, Int32)","visibility":"Public","body":"size = @@dbs.size\n@@dbs.each_key do |name|\n self.destroy(name)\nend\n{@@dbs.size, size}\n"}},{"id":"open(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"open(name:String,uri:String,strict=false):DB::Database-class-method","name":"open","doc":"Ensures only once DB connection pool by *name* is open.\nIf the DB connection pool *name* is already initialized, it is returned.\nRaises an error if *strict* is *true* and the DB connection pool *name* is\nalready opened.","summary":"

Ensures only once DB connection pool by name is open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":100,"url":null},"def":{"name":"open","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"if @@dbs.has_key?(name)\n if strict\n else\n return @@dbs[name]\n end\n raise(\"'#{name}' DB connection pool is already opened\")\nend\n@@dbs[name] = DB.open(uri)\n"}},{"id":"pool_open_connections(name:String):Int32-class-method","html_id":"pool_open_connections(name:String):Int32-class-method","name":"pool_open_connections","doc":"Gets the number of the connections opened in the pool of *name*.","summary":"

Gets the number of the connections opened in the pool of name.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Int32","args_html":"(name : String) : Int32","location":{"filename":"src/dbx.cr","line_number":142,"url":null},"def":{"name":"pool_open_connections","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"pool_stats = self.pool_stats(name)\nif pool_stats\nelse\n return 0\nend\npool_stats.open_connections\n"}},{"id":"pool_stats(name:String):DB::Pool::Stats?-class-method","html_id":"pool_stats(name:String):DB::Pool::Stats?-class-method","name":"pool_stats","doc":"Pool stats\nhttps://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html","summary":"

Pool stats https://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Pool::Stats?","args_html":"(name : String) : DB::Pool::Stats?","location":{"filename":"src/dbx.cr","line_number":137,"url":null},"def":{"name":"pool_stats","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Pool::Stats | ::Nil","visibility":"Public","body":"if self.db?(name)\n (self.db(name)).pool.stats\nend"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"around_query_or_exec(&block)-macro","html_id":"around_query_or_exec(&block)-macro","name":"around_query_or_exec","doc":"This macro allows injecting code to be run before and after the execution\nof the request. It should return the yielded value. It must be called with 1\nblock argument that will be used to pass the `args : Enumerable`.\nThis macro should be called at the top level, not from a method.\n\n> Be careful of the performance penalty that each hook may cause,\n be aware that your code will be executed at each query and exec.\n\n```\nDBX.around_query_or_exec do |args|\n puts \"before\"\n res = yield\n puts \"after\"\n\n puts res.class\n puts \"exec\" if res.is_a?(DB::ExecResult)\n puts \"query\" if res.is_a?(DB::ResultSet)\n\n puts \"with args:\"\n pp args\n\n res\nend\n```\n\nExample to measure query execution time:\n\n```\nDBX.around_query_or_exec do |args|\n start = Time.monotonic\n res = yield\n elapsed_time = Time.monotonic - start\n\n puts \"Query execution time: #{elapsed_time}\"\n res\nend\n```","summary":"

This macro allows injecting code to be run before and after the execution of the request.

","abstract":false,"args":[],"args_string":"(&block)","location":{"filename":"src/dbx.cr","line_number":185,"url":null},"def":{"name":"around_query_or_exec","args":[],"double_splat":null,"splat_index":null,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"visibility":"Public","body":" class ::DB::Statement\n def_around_query_or_exec do |args|\n \n{{ block.body }}\n\n \nend\n \nend\n \n"}}],"types":[{"html_id":"dbx/DBX/Adapter","path":"DBX/Adapter.html","kind":"module","full_name":"DBX::Adapter","name":"Adapter","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/adapter.cr","line_number":11,"url":null},{"filename":"src/adapter/pg.cr","line_number":12,"url":null},{"filename":"src/adapter/sqlite.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DB adapter(s) used by `DBX::QueryBuilder` and `DBX::ORM`.","summary":"

DB adapter(s) used by DBX::QueryBuilder and DBX::ORM.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"inject_pg-macro","html_id":"inject_pg-macro","name":"inject_pg","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/pg.cr","line_number":14,"url":null},"def":{"name":"inject_pg","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::PostgreSQL\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}},{"id":"inject_sqlite-macro","html_id":"inject_sqlite-macro","name":"inject_sqlite","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/sqlite.cr","line_number":14,"url":null},"def":{"name":"inject_sqlite","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::SQLite\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}}],"types":[{"html_id":"dbx/DBX/Adapter/Base","path":"DBX/Adapter/Base.html","kind":"class","full_name":"DBX::Adapter::Base","name":"Base","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/adapter.cr","line_number":13,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"}],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"Base adapter.","summary":"

Base adapter.

","class_methods":[{"id":"builder_class:QueryBuilder.class-class-method","html_id":"builder_class:QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class.","summary":"

Returns query builder class.

","abstract":false,"args":[],"args_string":" : QueryBuilder.class","args_html":" : QueryBuilder.class","location":{"filename":"src/adapter/adapter.cr","line_number":34,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder.class","visibility":"Public","body":"raise(NotImplementedError.new(\"'#{self}' model MUST define '#{self}.builder_class' method.\"))"}},{"id":"new_builder:QueryBuilder-class-method","html_id":"new_builder:QueryBuilder-class-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":29,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"constructors":[{"id":"new(db:DB::Database)-class-method","html_id":"new(db:DB::Database)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"args_string":"(db : DB::Database)","args_html":"(db : DB::Database)","location":{"filename":"src/adapter/adapter.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(db)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":true,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/adapter.cr","line_number":42,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"db:DB::Database-instance-method","html_id":"db:DB::Database-instance-method","name":"db","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/adapter/adapter.cr","line_number":19,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@db"}},{"id":"new_builder:QueryBuilder-instance-method","html_id":"new_builder:QueryBuilder-instance-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":24,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","path":"DBX/Adapter/PGQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":58,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for PostgreSQL.\n:inherit:","summary":"

QueryBuilder for PostgreSQL.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"ph(position:Int)-instance-method","html_id":"ph(position:Int)-instance-method","name":"ph","doc":"Adds placeholder specific to PostgreSQL.\nAdds placeholder for a SQL argument.","summary":"

Adds placeholder specific to PostgreSQL.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int)","args_html":"(position : Int)","location":{"filename":"src/adapter/pg.cr","line_number":65,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"#{@placeholder}#{position}\""}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PostgreSQL","path":"DBX/Adapter/PostgreSQL.html","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"PostgreSQL adapter","summary":"

PostgreSQL adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.\n> To get recorded data, PostgreSQL adapter use `RETURNING` SQL statement.\n *pk_name* and *pk_type* are useless and ignored,\n thanks PostgreSQL `RETURNING` that makes it simpler and more efficient :)","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/pg.cr","line_number":37,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create\\\" only, without other statement except the table. \\\"Test.create\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\n((query.insert(data)).returning(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/PostgreSQL/QueryBuilder","path":"DBX/Adapter/PostgreSQL/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::PostgreSQL::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/pg.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::PGQueryBuilder","aliased_html":"DBX::Adapter::PGQueryBuilder","const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLite","path":"DBX/Adapter/SQLite.html","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"SQLite adapter","summary":"

SQLite adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/sqlite.cr","line_number":34,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create!\\\" only, without other statement except the table. \\\"Test.create!\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\ntable_name = query.builder.table.gsub(\"\\\"\", \"\")\nlast_id = (query.insert(data)).exec!.last_insert_id\nif last_id.nil?\n raise(DB::NoResultsError.new(\"Cannot create\"))\nend\n(((query.table(table_name)).find(pk_name, last_id)).select(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/SQLite/QueryBuilder","path":"DBX/Adapter/SQLite/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::SQLite::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::SQLiteQueryBuilder","aliased_html":"DBX::Adapter::SQLiteQueryBuilder","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","path":"DBX/Adapter/SQLiteQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":69,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for SQLite.\n:inherit:","summary":"

QueryBuilder for SQLite.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/DBHashType","path":"DBX/DBHashType.html","kind":"alias","full_name":"DBX::DBHashType","name":"DBHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":62,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, DB::Database)","aliased_html":"Hash(String, DB::Database)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/Error","path":"DBX/Error.html","kind":"class","full_name":"DBX::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":65,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/Model/Error","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when an error occurred, related with `DB` or `DBX`.","summary":"

Raised when an error occurred, related with DB or DBX.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/NotSupportedError","path":"DBX/NotSupportedError.html","kind":"class","full_name":"DBX::NotSupportedError","name":"NotSupportedError","abstract":false,"superclass":{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},"ancestors":[{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":71,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when a method is not supported.\n\nThis can be used either to stub out method bodies,\nor when the method is not supported on the current adapter.","summary":"

Raised when a method is not supported.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM","path":"DBX/ORM.html","kind":"module","full_name":"DBX::ORM","name":"ORM","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model.cr","line_number":8,"url":null},{"filename":"src/orm/model_mixin.cr","line_number":8,"url":null},{"filename":"src/orm/model_query.cr","line_number":8,"url":null},{"filename":"src/orm/orm.cr","line_number":18,"url":null},{"filename":"src/orm/schema/schema.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DBX ORM (Object-Relational Mapping).","summary":"

DBX ORM (Object-Relational Mapping).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model","path":"DBX/ORM/Model.html","kind":"class","full_name":"DBX::ORM::Model","name":"Model","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":48,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Base class for all models.\n\nExample, creation of a model for a table `users`:\n\n```\nclass User < DBX::ORM::Model\n adapter :pg\n\n class Schema # < DBX::ORM::Schema#(User)\n field id : Int64?\n field name : String\n field about : String\n field age : Int32\n end\nend\n```\n\nCustomize `ModelQuery` used by `User` model:\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # Custom select\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Base class for all models.

","class_methods":[{"id":"connection:String-class-method","html_id":"connection:String-class-method","name":"connection","doc":"DB connection name used by this `Model` instance.","summary":"

DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/model.cr","line_number":176,"url":null},"def":{"name":"connection","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@conn_name"}},{"id":"db:DB::Database-class-method","html_id":"db:DB::Database-class-method","name":"db","doc":"Returns DB connection name used by this `Model` instance.","summary":"

Returns DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/orm/model.cr","line_number":181,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"DBX.db(connection)"}},{"id":"models-class-method","html_id":"models-class-method","name":"models","doc":"Returns array of all non-abstract subclasses of *DBX::ORM::Model.\n\n```\nDBX::ORM::Model.models # => [Contact, Address, User]\n```","summary":"

Returns array of all non-abstract subclasses of *DBX::ORM::Model.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model.cr","line_number":190,"url":null},"def":{"name":"models","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% models = @type.all_subclasses.select do |m|\n !m.abstract?\nend %}\n {% if !models.empty? %}\n [\n {% for model in models %}\n ::{{ model.name }},\n {% end %}\n ]\n {% else %}\n [] of ::DBX::ORM::Model.class\n {% end %}\n {% end %}"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model/Error","path":"DBX/ORM/Model/Error.html","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":53,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Model","kind":"class","full_name":"DBX::ORM::Model","name":"Model"},"doc":"Model error.","summary":"

Model error.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/ModelMixin","path":"DBX/ORM/ModelMixin.html","kind":"module","full_name":"DBX::ORM::ModelMixin(Model, ModelQuery)","name":"ModelMixin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model_mixin.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Mixin for `Model` class.\n> Automatically injected into the models.","summary":"

Mixin for Model class.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","html_id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","name":"create!","doc":"Creates a new resource and returns.","summary":"

Creates a new resource and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","args_html":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","location":{"filename":"src/orm/model_mixin.cr","line_number":33,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Model::Schema","visibility":"Public","body":"query.create!(data, returning: returning)"}},{"id":"delete(pk_value):ModelQuery-instance-method","html_id":"delete(pk_value):ModelQuery-instance-method","name":"delete","doc":"Deletes one resource by its primary key.","summary":"

Deletes one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":56,"url":null},"def":{"name":"delete","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete(Model.pk_name, pk_value)"}},{"id":"delete:ModelQuery-instance-method","html_id":"delete:ModelQuery-instance-method","name":"delete","doc":"Deletes one or more resources.","summary":"

Deletes one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":51,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete"}},{"id":"find(pk_value):ModelQuery-instance-method","html_id":"find(pk_value):ModelQuery-instance-method","name":"find","doc":"Find one resource by its primary key.","summary":"

Find one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":23,"url":null},"def":{"name":"find","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find(\"#{self.table_name}.#{Model.pk_name}\", pk_value)"}},{"id":"find:ModelQuery-instance-method","html_id":"find:ModelQuery-instance-method","name":"find","doc":"Find one or more resources.","summary":"

Find one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":18,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find"}},{"id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","name":"insert","doc":"Inserts a new resource.","summary":"

Inserts a new resource.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":28,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.insert(data)"}},{"id":"query:ModelQuery-instance-method","html_id":"query:ModelQuery-instance-method","name":"query","doc":"Creates a new `ModelQuery` instance.","summary":"

Creates a new ModelQuery instance.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":13,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"(ModelQuery.new(self.adapter)).table(self.table_name)"}},{"id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Updates one resource by its primary key.","summary":"

Updates one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_value, data : Hash | NamedTuple) : ModelQuery","args_html":"(pk_value, data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":46,"url":null},"def":{"name":"update","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(Model.pk_name, pk_value, data)"}},{"id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Update one or more resources.","summary":"

Update one or more resources.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":41,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(data)"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/ModelQuery","path":"DBX/ORM/ModelQuery.html","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery","abstract":false,"superclass":{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},"ancestors":[{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model_query.cr","line_number":35,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Generic `ModelQuery` class.\n> Automatically injected into the models.\n\nIf you want to customize the queries of a model, you can define\nyou own `ModelQuery` into this model.\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # A custom `select`\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Generic ModelQuery class.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = ModelQuery(Model).allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","html_id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\ntest = Test.create!(data)\nputs test.id\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","args_html":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","location":{"filename":"src/orm/model_query.cr","line_number":129,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"create!(data, as: Model::Schema, returning: returning, pk_name: Model.pk_name, pk_type: Model.pk_type)"}},{"id":"query_all-instance-method","html_id":"query_all-instance-method","name":"query_all","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":152,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"query_one-instance-method","html_id":"query_one-instance-method","name":"query_one","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":140,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"query_one!-instance-method","html_id":"query_one!-instance-method","name":"query_one!","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":146,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}},{"id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"rel","doc":"Refers to the result of a join in a defined `relation` property path.\n\n```\nusers = User\n .find\n .rel(\"groups\")\n .left_join(\"groups\", \"groups.id\", \"users.group_id\")\n .to_a\n```","summary":"

Refers to the result of a join in a defined relation property path.

","abstract":false,"args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":91,"url":null},"def":{"name":"rel","args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"r = Model::Schema.find_relation_from_path(path.to_s)\n@relations << r[:relation]\nselect_all.select_all(r[:model], table_alias)\n"}},{"id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects the relation fields.\nThis method is automatically called by the methods related to the joins with a model class.","summary":"

Selects the relation fields.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":63,"url":null},"def":{"name":"select_all","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if selected_all?(model_class, table_alias)\n return self\nend\nif table_alias\n table_alias = table_alias.to_s\n sql_fields = model_class.schema_class.fields.join(\",\") do |_, field|\n \"#{table_alias}.#{field[:name]}\"\n end\nelse\n sql_fields = model_class.schema_class.sql_fields\nend\nself.select(sql_fields)\n@rel_fields_selected[\"#{model_class}=>#{table_alias}\"] = true\nself\n"}},{"id":"select_all:ModelQuery(Model)-instance-method","html_id":"select_all:ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects all SQL fields.","summary":"

Selects all SQL fields.

","abstract":false,"args":[],"args_string":" : ModelQuery(Model)","args_html":" : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":47,"url":null},"def":{"name":"select_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if @fields_selected\n return self\nend\nself.select(Model::Schema.sql_fields)\n@fields_selected = true\nself\n"}},{"id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","html_id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the relation fields are selected, `false` otherwise.\nSee `select_rel_fields`","summary":"

Returns true if the relation fields are selected, false otherwise.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","location":{"filename":"src/orm/model_query.cr","line_number":57,"url":null},"def":{"name":"selected_all?","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@rel_fields_selected.has_key?(\"#{model_class}=>#{table_alias}\")"}},{"id":"selected_all?:Bool-instance-method","html_id":"selected_all?:Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the model fields are selected, `false` otherwise.\nSee `select_all`","summary":"

Returns true if the model fields are selected, false otherwise.

","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/orm/model_query.cr","line_number":42,"url":null},"def":{"name":"selected_all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@fields_selected"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":188,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Shortcut, same as `query_all`.","summary":"

Shortcut, same as #query_all.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":182,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":177,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o-instance-method","html_id":"to_o-instance-method","name":"to_o","doc":"Shortcut, same as `query_one`.","summary":"

Shortcut, same as #query_one.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":166,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":172,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!-instance-method","html_id":"to_o!-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!`.","summary":"

Shortcut, same as #query_one!.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":160,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema","path":"DBX/ORM/Schema.html","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":14,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"FIELDS","name":"FIELDS","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null},{"id":"RELATIONS","name":"RELATIONS","value":"{} of String => ASTNode","doc":null,"summary":null}],"included_modules":[{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"`Model` Schema.","summary":"

Model Schema.

","class_methods":[{"id":"fields:MetaFieldHash-class-method","html_id":"fields:MetaFieldHash-class-method","name":"fields","doc":"Returns all SQL fields definitions.","summary":"

Returns all SQL fields definitions.

","abstract":false,"args":[],"args_string":" : MetaFieldHash","args_html":" : MetaFieldHash","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"MetaFieldHash","visibility":"Public","body":"@@fields"}},{"id":"from_rs(rs:DB::ResultSet)-class-method","html_id":"from_rs(rs:DB::ResultSet)-class-method","name":"from_rs","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"from_rs","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n objs = Array(self).new\n rs.each do\n objs << (self.new(rs))\n end\n objs\nensure\n rs.close\nend"}},{"id":"sql_fields:String-class-method","html_id":"sql_fields:String-class-method","name":"sql_fields","doc":"Returns the SQL fields of the model separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_fields"}},{"id":"sql_rel_fields:String-class-method","html_id":"sql_rel_fields:String-class-method","name":"sql_rel_fields","doc":"Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_rel_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_rel_fields"}}],"constructors":[{"id":"new(rs:DB::ResultSet)-class-method","html_id":"new(rs:DB::ResultSet)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"new","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"instance = allocate\ninstance.initialize(__set_for_db_serializable: rs)\nif instance.responds_to?(:finalize)\n GC.add_finalizer(instance)\nend\ninstance\n"}},{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"args_string":"(pull : JSON::PullParser)","args_html":"(pull : JSON::PullParser)","location":{"filename":"src/orm/schema/schema.cr","line_number":23,"url":null},"def":{"name":"new","args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_from_json_pull_parser(pull)"}}],"instance_methods":[{"id":"_pk-instance-method","html_id":"_pk-instance-method","name":"_pk","doc":"Same as `_pk` but may return `nil` when the record hasn't been saved\ninstead of raising.","summary":"

Same as #_pk but may return nil when the record hasn't been saved instead of raising.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":40,"url":null},"def":{"name":"_pk","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.id"}},{"id":"_pk!-instance-method","html_id":"_pk!-instance-method","name":"_pk!","doc":"Always returns this record's primary key value, even when the primary key\nisn't named `_pk`.","summary":"

Always returns this record's primary key value, even when the primary key isn't named #_pk.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":32,"url":null},"def":{"name":"_pk!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk.not_nil!"}},{"id":"_ukey-instance-method","html_id":"_ukey-instance-method","name":"_ukey","doc":"Unique (virtual) key used to compare the uniqueness of models.\nBy default this method returns the primary key (`_pk`) value.\n\nThis method avoid to rely directly on the primary key in case there is none in\nthe structure of the SQL table (even if there should always be one).\nUsed in the relation algorithm.\nAlso, can be useful when there is a need to check the uniqueness in other cases.\n\nIf for some reason your model does not have a primary key,\nyou can override this method to return a unique result\nrelated to the fields in your table, for example:\n\n```\n@[DB::Field(ignore: true)]\n@[JSON::Field(ignore: true)]\ndef _ukey\n \"#{self.group_id}.#{self.user_id}\"\nend\n```","summary":"

Unique (virtual) key used to compare the uniqueness of models.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":65,"url":null},"def":{"name":"_ukey","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk"}}],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Schema/MetaField","path":"DBX/ORM/Schema/MetaField.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaField","name":"MetaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":16,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String)","aliased_html":"{name: String, rel_name: String, sql: String, rel_sql: String}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/MetaFieldHash","path":"DBX/ORM/Schema/MetaFieldHash.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaFieldHash","name":"MetaFieldHash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":17,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String))","aliased_html":"Hash(String, {name: String, rel_name: String, sql: String, rel_sql: String})","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/RelationDef","path":"DBX/ORM/Schema/RelationDef.html","kind":"alias","full_name":"DBX::ORM::Schema::RelationDef","name":"RelationDef","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool)","aliased_html":"{name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/SchemaField","path":"DBX/ORM/SchemaField.html","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/field.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"field(name)-macro","html_id":"field(name)-macro","name":"field","doc":"Defines a SQL field.","summary":"

Defines a SQL field.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"args_string":"(name)","location":{"filename":"src/orm/schema/def/field.cr","line_number":10,"url":null},"def":{"name":"field","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if name.is_a?(TypeDeclaration) %}\n {% full_name = \"#{model_class}.#{name.var}\"\nif FIELDS[full_name].nil?\n FIELDS[full_name] = HashLiteral(String, ASTNode).new\nend\nFIELDS[full_name] = {model: model_class, name: name.var, full_name: full_name.id, rel_name: \"__#{model_class}_#{name.var}\", type: name.type, type_class: \"#{name.type.is_a?(Union) ? \"(#{name.type})\".id : name.type}.class\".id, default: name.value || \"nil\".id}\n %}\n\n @{{ name.var }} : {{ name.type }}{% if name.value %} = {{ name.value }}{% end %}\n def {{ name.var }} : {{ name.type }}\n @{{ name.var }}\n end\n\n def {{ name.var }}=(value : {{ name.type }})\n @{{ name.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.field doesn't support \" + name.class_name) %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","path":"DBX/ORM/SchemaInjectFields.html","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/inject_fields.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_fields-macro","html_id":"orm_schema_inject_fields-macro","name":"orm_schema_inject_fields","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_fields.cr","line_number":9,"url":null},"def":{"name":"orm_schema_inject_fields","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" @@fields : MetaFieldHash = MetaFieldHash.new\n @@sql_fields : String = \"\"\n @@sql_rel_fields : String = \"\"\n\n \n# Returns all SQL fields definitions.\n\n def self.fields : MetaFieldHash\n @@fields\n \nend\n\n \n# Returns the SQL fields of the model separated by a comma (table.column, ...).\n\n def self.sql_fields : String\n @@sql_fields\n \nend\n\n \n# Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).\n\n def self.sql_rel_fields : String\n @@sql_rel_fields\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","path":"DBX/ORM/SchemaInjectForFinal.html","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal","abstract":false,"superclass":null,"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"locations":[{"filename":"src/orm/schema/inject_for_final.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_for_final-macro","html_id":"orm_schema_inject_for_final-macro","name":"orm_schema_inject_for_final","doc":"Finish for the final `Schema` class.","summary":"

Finish for the final Schema class.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_for_final.cr","line_number":13,"url":null},"def":{"name":"orm_schema_inject_for_final","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% model_relations = {} of Symbol => ASTNode %}\n\n\n \n{% for path, dec in RELATIONS %}\n {% if model_class == dec[:from_model] %}\n {% model_relations[path] = dec %}\n {% end %}\n {% end %}\n\n\n \n{% consts = @type.constants.map(&.symbolize) %}\n\n \n{% if consts.includes?(:DBValue) %}{% else %}\n alias DBValue = DBX::QueryBuilder::DBValue\n {% end %}\n\n\n \n# Returns model table name.\n\n def self.table_name : String\n model_class.table_name\n \nend\n\n \n# Returns model class.\n\n def self.model_class : \n{{ model_class }}\n.class\n \n{{ model_class }}\n\n \nend\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @@fields[{{ full_name }}] = {\n name: \"{{ dec[:name] }}\",\n rel_name: {{ dec[:rel_name] }},\n sql: \"#{table_name}.{{ dec[:name] }}\",\n rel_sql: \"#{table_name}.{{ dec[:name] }} AS {{ dec[:rel_name].id }}\"\n }\n {% end %}\n {% end %}\n\n\n @@sql_fields : String = self.fields.join(\",\") \n{ |_, f| f[:sql] }\n @@sql_rel_fields : String = self.fields.join(\",\") \n{ |_, f| f[:rel_sql] }\n\n \n# All DB fields of the `\n{{ model_class }}\n` model.\n\n alias FieldsDef = \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type_class] }} },\n {% end %}\n {% end %}\n\n }\n\n \n# --------------------------------------------------------------------------\n\n\n \n# Creates a new `\n{{ model_class }}\n` instance.\n\n \n# > Useful to create (insert) a new entry in the DB.\n\n def initialize(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @{{ dec[:name] }} : {{ dec[:type] }} = {{ dec[:default] }},\n {% end %}\n {% end %}\n\n )\n \nend\n\n \n# Creates a new _strict_ `\n{{ model_class }}\n` instance without using default value.\n\n \n# > Can be populated with data from the DB.\n\n def self.new_strict(\n \n{% args = [] of ASTNode %}\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }} : {{ dec[:type] }},\n {% args << dec[:name] %}\n {% end %}\n {% end %}\n\n )\n \n{{ model_class }}\n::Schema.new(\n{{ args.splat }}\n)\n \nend\n\n private def self.process_next_rel(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n schema : \n{{ model_class }}\n::Schema,\n rel_idx : Int32,\n cols_readed : Int32\n )\n next_rel = relations[rel_idx]\n\n case next_rel[:name]\n \n{% for path, dec in model_relations %}\n {% if model_class == dec[:from_model] %}\n when {{ dec[:name] }}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} : {{ dec[:model_class] }}::Schema? = nil\n\n {% if dec[:has_many] %}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} = schema.{{ dec[:name].id }}.last?\n {% end %}\n\n if rel_schema = {{ dec[:model_class] }}::Schema.from_rs(\n rs,\n relations,\n rel_idx + 1, # move cursor to next rel\n cols_readed,\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }},\n )\n schema.{{ dec[:name].id }} {{ dec[:has_one] ? \"=\".id : \"<<\".id }} rel_schema.as({{ dec[:model_class] }}::Schema)\n end\n {% end %}\n {% end %}\n\n \nelse\n raise DBX::Error.new %(Cannot resolve the relation \"#{next_rel[:model_class]}.#{next_rel[:name]}\")\n \nend\n \nend\n\n \n# Creates an instance from a relation.\n\n def self.from_rs(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n rel_idx : Int32 = 0,\n cols_readed : Int32 = 0,\n last_schema : \n{{ model_class }}\n::Schema? = nil,\n ) : Schema?\n if relations.size == 0\n raise DBX::Error.new \"Bad method call. This method must be called only for a query with relation(s).\"\n \nend\n\n cols_total = rs.column_count\n\n \n{% cols_readed_initial = 0 %}\n\n\n \n# Fix: PG::ResultSet#read returned a String. A (Int64 | Nil) was expected.\n\n \n# Prevent this error when a resource is found without its relation(s) (like a conventional LEFT JOIN).\n\n should_not_read_first_field = false\n\n \n# first iter or try to check with pk for deep iter\n\n if !last_schema || cols_readed == 0 || \n{{ model_class }}\n.pk_name == rs.column_name(cols_readed)\n first_field = rs.read\n should_not_read_first_field = true\n \n{% cols_readed_initial += 1 %}\n\n return nil if first_field.nil?\n \nend\n\n schema = \n{{ model_class }}\n::Schema.new_strict(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: if should_not_read_first_field\n should_not_read_first_field = false\n first_field.as({{ dec[:type] }})\n else\n rs.read({{ dec[:type] }})\n end,\n {% cols_readed_initial += 1 %}\n {% end %}\n {% end %}\n\n )\n\n \n# avoid duplicate for deep iteration(s)\n\n if !last_schema.nil? && last_schema._ukey == schema._ukey\n schema = last_schema\n \nend\n\n cols_readed += \n{{ cols_readed_initial }}\n\n\n if rel_idx + 1 <= relations.size\n self.process_next_rel(rs, relations, schema, rel_idx, cols_readed)\n return schema\n \nend\n\n return schema if cols_total == cols_readed\n schema\n \nend\n\n \n# --------------------------------------------------------------------------\n\n\n def self.fields_def : FieldsDef\n \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type] }} },\n {% end %}\n {% end %}\n\n }\n \nend\n\n def self.relations_def : Hash(String, RelationDef)\n @@relations_def\n \nend\n\n def self.add_relation(path : String | Symbol, dec : RelationDef) : Schema.class\n full_path = \"\n{{ model_class }}\n.#{path}\"\n\n if @@relations_def.has_key?(full_path)\n raise DBX::Error.new %(relation \"#{full_path}\" already defined)\n \nend\n\n @@relations_def[full_path] = dec\n self\n \nend\n\n \n# Lookup the path in relations def.\n\n def self.lookup_relation_def?(path : Symbol | String) : \n{String, RelationDef?}\n model_name = \"#{model_class}\"\n path = path.to_s\n cursor_path = \"#{model_name}.#{path}\"\n\n if rel_found = @@relations_def[cursor_path]?\n return \n{ cursor_path, rel_found }\n \nend\n\n path_a = path.split(\".\")\n\n \n# not found above\n\n return \n{cursor_path, nil} if path_a.size == 1\n\n \n# lookup the rest\n\n cursor_path = \"#{model_name}.#{path_a.first}\"\n path_a.size.times do |i|\n next_part_i = i + 1\n\n if rel_found = @@relations_def[\"#{cursor_path}\"]?\n cursor_path = \"#{rel_found[:model_class]}.#{path_a[next_part_i]}\"\n \nend\n\n \n# if end of search\n\n break rel_found if path_a.size == next_part_i + 1\n \nend\n\n \n{cursor_path, rel_found}\n \nend\n\n \n# Find a relation from its path.\n\n def self.find_relation_from_path(path : String) : \n{\n relation: RelationDef,\n cursor_path: String,\n field: String,\n model: DBX::ORM::Model.class\n }\n raise DBX::Error.new \"Relation path is empty\" if path.empty?\n cursor_path, relation_def = self.lookup_relation_def?(path)\n\n \n# r_model is the rel_model if the path is not deep, ref_model for deep path\n\n unless relation_def && (r_model = relation_def[:model_class])\n parts = path.split('.')\n\n if parts.size > 2\n raise DBX::Error.new %(\n Relation path to long: \"#{path}\".\n The depth of a relationship selection cannot exceed 2 levels (max is \"#{parts[...-1].join(\".\")}\").\n PR is welcome ;-\\)\n )\n \nend\n\n raise DBX::Error.new %(Undefined relation \"#{path}\")\n \nend\n\n parts = path.split('.')\n\n \n# if not deep\n\n if parts.size == 1\n return \n{ relation: relation_def, cursor_path: cursor_path, field: path, model: r_model }\n \nend\n\n ref_model = r_model\n rel_field = parts.last\n\n \n{% i = 0 %}\n\n \n{% cond_start = \"if\".id %}\n\n \n{% for path, dec in RELATIONS %}\n {% i += 1 %}\n {% if i != 1 %}\n {% cond_start = \"elsif\".id %}\n {% end %}\n\n # if the model referant is found\n {{ cond_start }} ref_model == {{ dec[:from_model] }} && {{ dec[:name] }} == rel_field\n # relation model is resolved\n rel_model = {{ dec[:model_class] }}\n\n relation_def = {\n name: {{ dec[:name] }},\n model_class: {{ dec[:model_class] }},\n has_one: {{ dec[:has_one] }},\n has_many: {{ dec[:has_many] }}\n }\n {% end %}\n\n \n{{ \"end\".id }}\n \n# end: cond_start\n\n\n raise DBX::Error.new %(Model not found for relation path: \"#{path}\") unless rel_model\n\n \n{ relation: relation_def, cursor_path: cursor_path, field: rel_field, model: rel_model }\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaRelation","path":"DBX/ORM/SchemaRelation.html","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/relation.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"relation(var_decl,**opt)-macro","html_id":"relation(var_decl,**opt)-macro","name":"relation","doc":"Defines a relation.","summary":"

Defines a relation.

","abstract":false,"args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"args_string":"(var_decl, **opt)","location":{"filename":"src/orm/schema/def/relation.cr","line_number":10,"url":null},"def":{"name":"relation","args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"double_splat":{"name":"opt","doc":null,"default_value":"","external_name":"opt","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if var_decl.is_a?(TypeDeclaration) %}\n {% if var_decl.type.stringify.starts_with?(\"Array\")\n rel_model = var_decl.type.stringify[6...-1].id\n rel_schema_type = \"Array(#{rel_model}::Schema)\".id\n has_one = false\n has_many = true\nelse\n rel_model = var_decl.type\n rel_schema_type = \"#{rel_model}::Schema\".id\n has_one = true\n has_many = false\nend %}\n\n unless {{ var_decl.type }}.is_a?(DBX::ORM::Model.class) || {{ rel_model }}.is_a?(DBX::ORM::Model.class)\n raise \"{{ model_class }}: relation must be a Model class but is a {{ var_decl.type }}\"\n end\n\n {% RELATIONS[\"#{model_class}.#{var_decl.var}\"] = {name: \"#{var_decl.var}\", model_class: rel_model, from_model: model_class, has_one: has_one, has_many: has_many} %}\n\n self.add_relation(\"{{ var_decl.var }}\", {\n name: \"{{ var_decl.var }}\",\n model_class: {{ rel_model }},\n has_one: {{ has_one }},\n has_many: {{ has_many }},\n })\n\n @[JSON::Field(emit_null: false)]\n @[DB::Field(ignore: true)]\n @{{ var_decl.var }} : {{ rel_schema_type }}?\n\n def {{ var_decl.var }} : {{ rel_schema_type }}{% if has_one %}?{% end %}\n {% if has_many %}\n @{{ var_decl.var }} = [] of {{ rel_model }}::Schema unless @{{ var_decl.var }}\n return @{{ var_decl.var }}.not_nil!\n {% end %}\n\n @{{ var_decl.var }}\n end\n\n def {{ var_decl.var }}=(value : {{ rel_schema_type }})\n @{{ var_decl.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.relation doesn't support #{var_decl.class_name}\") %}\n {% end %}\n\n \n"}}],"types":[]}]},{"html_id":"dbx/DBX/Query","path":"DBX/Query.html","kind":"class","full_name":"DBX::Query","name":"Query","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/executor.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/ModelQuery","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query executor.\nSee also: https://crystal-lang.github.io/crystal-db/api/latest/DB/QueryMethods.html","summary":"

Query executor.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"build:Tuple-instance-method","html_id":"build:Tuple-instance-method","name":"build","doc":"Builds current query and returns `sql, args`.\nSee `DBX::QueryBuilder#build` method.","summary":"

Builds current query and returns sql, args.

","abstract":false,"args":[],"args_string":" : Tuple","args_html":" : Tuple","location":{"filename":"src/query_builder/executor.cr","line_number":170,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple","visibility":"Public","body":"@builder.build"}},{"id":"builder:DBX::QueryBuilder-instance-method","html_id":"builder:DBX::QueryBuilder-instance-method","name":"builder","doc":"Returns `DBX::QueryBuilder` instance used in current `Query` instance.","summary":"

Returns DBX::QueryBuilder instance used in current Query instance.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder","args_html":" : DBX::QueryBuilder","location":{"filename":"src/query_builder/executor.cr","line_number":175,"url":null},"def":{"name":"builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder","visibility":"Public","body":"@builder"}},{"id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {String, Int32},\n returning: {:name, :age}\n)\n# => {\"Baby\", 1}\n\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {name: String, age: Int32},\n returning: {:name, :age}\n)\n# => {name: \"Baby\", age: 1}\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/query_builder/executor.cr","line_number":198,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@adapter.create!(self, data, types, returning, pk_name, pk_type)"}},{"id":"exec-instance-method","html_id":"exec-instance-method","name":"exec","doc":":ditto:\nReturns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: Returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":42,"url":null},"def":{"name":"exec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n exec!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"exec!-instance-method","html_id":"exec!-instance-method","name":"exec!","doc":"Executes current built query that is expected to return an `DB::ExecResult`.","summary":"

Executes current built query that is expected to return an DB::ExecResult.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":22,"url":null},"def":{"name":"exec!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_method = @builder.query_method\nsql, args = @builder.build\ner = @db.exec(sql, args: args)\nif (((((query_method == (:insert)) || (query_method == (:update_one))) || (query_method == (:update))) || (query_method == (:delete_one))) || (query_method == (:delete))) && (er.rows_affected == 0)\n raise(DB::NoResultsError.new(\"DB::ExecResult: No rows affected\"))\nend\ner\n"}},{"id":"query-instance-method","html_id":"query-instance-method","name":"query","doc":"Executes current built query that is expected to return one or more results.\n\n```\ntests = [] of Array(String | Int32)\nrs = query.find(:tests).select(:name, :age).query\n\nbegin\n while rs.move_next\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nensure\n rs.close\nend\n```","summary":"

Executes current built query that is expected to return one or more results.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":64,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args)\n"}},{"id":"query(&)-instance-method","html_id":"query(&)-instance-method","name":"query","doc":"Executes current built query and yields a `DB::ResultSet` with the results.\nThe `DB::ResultSet` is closed automatically.\n\n```\ntests = [] of Array(String | Int32)\nquery.find(:tests).select(:name, :age).query do |rs|\n rs.each do\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nend\n```","summary":"

Executes current built query and yields a DB::ResultSet with the results.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":82,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_all(astypes)-instance-method","html_id":"query_all(astypes)-instance-method","name":"query_all","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":88,"url":null},"def":{"name":"query_all","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args, as: types)\n"}},{"id":"query_all(&)-instance-method","html_id":"query_all(&)-instance-method","name":"query_all","doc":"Executes current built query and yields a `DB::ResultSet` positioned\nat the beginning of each row, returning an `Array` of the values of the blocks.","summary":"

Executes current built query and yields a DB::ResultSet positioned at the beginning of each row, returning an Array of the values of the blocks.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":95,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_each(&)-instance-method","html_id":"query_each(&)-instance-method","name":"query_each","doc":"Executes current built query and yields the `DB::ResultSet` once per each row.","summary":"

Executes current built query and yields the DB::ResultSet once per each row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":101,"url":null},"def":{"name":"query_each","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_each(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_one(astypes)-instance-method","html_id":"query_one(astypes)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":114,"url":null},"def":{"name":"query_one","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one!(types)\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one(&)-instance-method","html_id":"query_one(&)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":129,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one! do |rs|\n yield rs\n end\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one!(astypes)-instance-method","html_id":"query_one!(astypes)-instance-method","name":"query_one!","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":107,"url":null},"def":{"name":"query_one!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args, as: types)\n"}},{"id":"query_one!(&)-instance-method","html_id":"query_one!(&)-instance-method","name":"query_one!","doc":"Executes current built query that expects at most a single row and yields\na `DB::ResultSet` positioned at that first row.","summary":"

Executes current built query that expects at most a single row and yields a DB::ResultSet positioned at that first row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":122,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"raw_query(&):Query-instance-method","html_id":"raw_query(&):Query-instance-method","name":"raw_query","doc":"See `DBX::QueryBuilder#query`","summary":"

See DBX::QueryBuilder#query

","abstract":false,"args":[],"args_string":"(&) : Query","args_html":"(&) : Query","location":{"filename":"src/query_builder/executor.cr","line_number":161,"url":null},"def":{"name":"raw_query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"Query","visibility":"Public","body":"@builder.query do\n with QueryBuilderScope.new(@builder) yield\nend\nself\n"}},{"id":"scalar-instance-method","html_id":"scalar-instance-method","name":"scalar","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.\nSo the type MUST be nillable:\n\n```\nquery\n .find(:tests)\n .select(:name)\n .where(:name, \"Terminator\")\n .scalar\n .as(String?)\n# => String | Nil\n```","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":154,"url":null},"def":{"name":"scalar","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n scalar!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"scalar!-instance-method","html_id":"scalar!-instance-method","name":"scalar!","doc":"Executes current built query and returns a single scalar value.","summary":"

Executes current built query and returns a single scalar value.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":136,"url":null},"def":{"name":"scalar!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.scalar(sql, args: args)\n"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as #query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":229,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a(&)-instance-method","html_id":"to_a(&)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(&block)`.","summary":"

Shortcut, same as #query_all(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":234,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all do |rs|\n yield rs\nend"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as #query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":214,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o(&)-instance-method","html_id":"to_o(&)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(&block)`.","summary":"

Shortcut, same as #query_one(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":224,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one do |rs|\n yield rs\nend"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as #query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":209,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!(&)-instance-method","html_id":"to_o!(&)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(&block)`.","summary":"

Shortcut, same as #query_one!(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":219,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one! do |rs|\n yield rs\nend"}}],"macros":[{"id":"method_missing(call)-macro","html_id":"method_missing(call)-macro","name":"method_missing","doc":null,"summary":null,"abstract":false,"args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"args_string":"(call)","location":{"filename":"src/query_builder/executor.cr","line_number":238,"url":null},"def":{"name":"method_missing","args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% if true %}\n {% if block = call.block %}\n # See `DBX::QueryBuilder#{{ call.name }}(&block` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }}) {{ block }}\n self\n end\n {% else %}\n # See `DBX::QueryBuilder#{{ call.name }}` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }})\n self\n end\n {% end %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/QueryBuilder","path":"DBX/QueryBuilder.html","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/builder.cr","line_number":9,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":10,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":9,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":"Quoting character.","summary":"

Quoting character.

"}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder"},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query builder.","summary":"

Query builder.

","class_methods":[],"constructors":[{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Creates a new `QueryBuilder`.","summary":"

Creates a new QueryBuilder.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_arg(value):String-instance-method","html_id":"add_arg(value):String-instance-method","name":"add_arg","doc":"Adds value to *args* and returns the `placeholder`.","summary":"

Adds value to args and returns the placeholder.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":49,"url":null},"def":{"name":"add_arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"if value.is_a?(Symbol)\n value = value.to_s\nend\n@args << value\nph(@args.size)\n"}},{"id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":58,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |_, value|\n add_arg(value)\nend"}},{"id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : Array, sep = ", ") : String","args_html":"(data : Array, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":63,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |value|\n add_arg(value)\nend"}},{"id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_kv_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a combined statement.\nExample: `field1 = $1, field2 = $2, field3 = $3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a combined statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":70,"url":null},"def":{"name":"add_args_and_kv_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |field, value|\n \"#{field} = #{add_arg(value)}\"\nend"}},{"id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":212,"url":null},"def":{"name":"alter","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"alter(command, field, data_type)\ntable(table)\n"}},{"id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(command : String, field : String, data_type = "") : QueryBuilder","args_html":"(command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":206,"url":null},"def":{"name":"alter","args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :alter\n@options = {command: command, field: field, data_type: data_type}\nself\n"}},{"id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"analyze\ntable(table)\n"}},{"id":"analyze:QueryBuilder-instance-method","html_id":"analyze:QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :analyze\nself\n"}},{"id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","name":"avg","doc":"Adds `AVG` to the current query.","summary":"

Adds AVG to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"avg","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"avg = \"AVG(#{field})\"\nif name.nil?\nelse\n avg = avg + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? avg : \"#{@select}, #{avg}\"\nself\n"}},{"id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","name":"between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":301,"url":null},"def":{"name":"between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nelse\n \" #{and_or} #{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nend)\nself\n"}},{"id":"build:SQLandArgsType-instance-method","html_id":"build:SQLandArgsType-instance-method","name":"build","doc":"Builds the current query and returns SQL (string) and arguments (array).\n\n```\nsql, args = builder.build\n```","summary":"

Builds the current query and returns SQL (string) and arguments (array).

","abstract":false,"args":[],"args_string":" : SQLandArgsType","args_html":" : SQLandArgsType","location":{"filename":"src/query_builder/builder.cr","line_number":34,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"SQLandArgsType","visibility":"Public","body":"{% if true %}\n case @query_method\n {% for method in [:find, :insert, :update, :delete, :drop, :alter, :query, :analyze, :check, :checksum, :optimize, :repair] %}\n when :{{ method.id }} then end_query(build_query_{{ method.id }})\n {% end %}\n when :update_one then end_query(build_query_update)\n when :delete_one then end_query(build_query_delete)\n else\n raise Error.new \"Bad QueryBuilder method. #{@query_method}\"\n end\n {% end %}"}},{"id":"check:QueryBuilder-instance-method","html_id":"check:QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :check\nself\n"}},{"id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"check\ntable(table)\n"}},{"id":"checksum:QueryBuilder-instance-method","html_id":"checksum:QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :checksum\nself\n"}},{"id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"checksum\ntable(table)\n"}},{"id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","name":"count","doc":"Adds `COUNT` to the current query.","summary":"

Adds COUNT to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"count","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"count = \"COUNT(#{field})\"\nif name.nil?\nelse\n count = count + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? count : \"#{@select}, #{count}\"\nself\n"}},{"id":"delete:QueryBuilder-instance-method","html_id":"delete:QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":165,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :delete\nself\n"}},{"id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":170,"url":null},"def":{"name":"delete","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\ntable(table)\n"}},{"id":"delete(pk_name,pk_value):QueryBuilder-instance-method","html_id":"delete(pk_name,pk_value):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":175,"url":null},"def":{"name":"delete","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\n@query_method = :delete_one\nself.where(pk_name, pk_value)\n"}},{"id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","html_id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":195,"url":null},"def":{"name":"drop","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"drop(check_exists)\ntable(table)\n"}},{"id":"drop(check_exists=true):QueryBuilder-instance-method","html_id":"drop(check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(check_exists = true) : QueryBuilder","args_html":"(check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":189,"url":null},"def":{"name":"drop","args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :drop\n@options = check_exists\nself\n"}},{"id":"find(pk_name,pk_value):QueryBuilder-instance-method","html_id":"find(pk_name,pk_value):QueryBuilder-instance-method","name":"find","doc":"Finds one resource by its primary key.\n\nSame as:\n\n```\nbuilder.find.where(pk_name, pk_value)\n```","summary":"

Finds one resource by its primary key.

","abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":101,"url":null},"def":{"name":"find","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find.where(pk_name, pk_value)"}},{"id":"find:QueryBuilder-instance-method","html_id":"find:QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":63,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :find\nself\n"}},{"id":"find(&):QueryBuilder-instance-method","html_id":"find(&):QueryBuilder-instance-method","name":"find","doc":"Adds `find` to current query\nand defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Adds #find to current query and defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":88,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\n@table = \"#{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"args_string":"(table_name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table_name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":68,"url":null},"def":{"name":"find","args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\ntable(table_name)\n"}},{"id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_join","doc":"Adds `FULL JOIN` to the current query.","summary":"

Adds FULL JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL\")"}},{"id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_outer_join","doc":"Adds `FULL OUTER JOIN` to the current query.","summary":"

Adds FULL OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL OUTER\")"}},{"id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"group_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"args_string":"(field : OneOrMoreFieldsType) : QueryBuilder","args_html":"(field : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":396,"url":null},"def":{"name":"group_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@group_by = field.is_a?(FieldsType) ? field.join(\", \") : field.to_s\nself\n"}},{"id":"having(&):QueryBuilder-instance-method","html_id":"having(&):QueryBuilder-instance-method","name":"having","doc":"Defines in raw form the SQL statement of `HAVING`.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(:tests).group_by(:payment).having { \"SUM(price) > 40\" }\n```\n\nGenerates:\n\n```\nSELECT * FROM tests GROUP_BY payment HAVING SUM(person) > 40\n```","summary":"

Defines in raw form the SQL statement of HAVING.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":425,"url":null},"def":{"name":"having","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"having","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":402,"url":null},"def":{"name":"having","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = if @operators.includes?(op_or_val.to_s)\n \"#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \"#{field} > #{add_arg(op_or_val)}\"\nend\nself\n"}},{"id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","name":"in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":275,"url":null},"def":{"name":"in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"keys = [] of String\nvalues.each do |val|\n keys << (add_arg(val))\nend\n@where = @where + (if @where.empty?\n \"#{field} #{type}IN (#{keys.join(\", \")})\"\nelse\n \" #{and_or} #{field} #{type}IN (#{keys.join(\", \")})\"\nend)\nself\n"}},{"id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"inner_join","doc":"Adds `INNER JOIN` to the current query.","summary":"

Adds INNER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"inner_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"INNER\")"}},{"id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":119,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :insert\n@data = to_data_h(data)\nself\n"}},{"id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":125,"url":null},"def":{"name":"insert","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"insert(data)\ntable(table)\n"}},{"id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","html_id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","name":"join","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":166,"url":null},"def":{"name":"join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + (if field2.nil?\n \" #{type} JOIN #{table} ON #{field1}\"\nelse\n \" #{type} JOIN #{table} ON #{field1} = #{field2}\"\nend)\nself\n"}},{"id":"join(&):QueryBuilder-instance-method","html_id":"join(&):QueryBuilder-instance-method","name":"join","doc":"Adds a raw `join` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").join { \"\n INNER JOIN T2 ON T1.a = T2.a\n AND T1.b = T2.b\n OR T1.b = #{q(some_value_to_quote)}\n\" }\n .join { \"LEFT JOIN payments p USING (product_id)\" }\n```","summary":"

Adds a raw #join to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":193,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"join:String-instance-method","html_id":"join:String-instance-method","name":"join","doc":"Returns jointure. Returns empty string if no jointure has been defined.\n\n```\nputs builder.join unless builder.join.blank? # or .empty?\n```","summary":"

Returns jointure.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":215,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@join"}},{"id":"last_query:String-instance-method","html_id":"last_query:String-instance-method","name":"last_query","doc":"Returns the last query.","summary":"

Returns the last query.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder.cr","line_number":295,"url":null},"def":{"name":"last_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@last_query"}},{"id":"last_query_method:Symbol?-instance-method","html_id":"last_query_method:Symbol?-instance-method","name":"last_query_method","doc":"Returns the last query method.","summary":"

Returns the last query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":300,"url":null},"def":{"name":"last_query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@last_query_method"}},{"id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_join","doc":"Adds `LEFT JOIN` to the current query.","summary":"

Adds LEFT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT\")"}},{"id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_outer_join","doc":"Adds `LEFT OUTER JOIN` to the current query.","summary":"

Adds LEFT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT OUTER\")"}},{"id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","name":"like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":322,"url":null},"def":{"name":"like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}LIKE #{add_arg(value)}\"\nelse\n \" #{and_or} #{field} #{type}LIKE #{add_arg(value)}\"\nend)\nself\n"}},{"id":"limit:String-instance-method","html_id":"limit:String-instance-method","name":"limit","doc":"Returns `limit` value. Returns empty string if no limit has been defined.\n\n```\nputs builder.limit unless builder.limit.blank? # or .empty?\n```","summary":"

Returns #limit value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":359,"url":null},"def":{"name":"limit","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@limit"}},{"id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","html_id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","name":"limit","doc":null,"summary":null,"abstract":false,"args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"args_string":"(limit, limit_end = nil) : QueryBuilder","args_html":"(limit, limit_end = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":343,"url":null},"def":{"name":"limit","args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if limit_end.nil?\n @limit = add_arg(limit)\nelse\n @limit = add_arg(limit_end)\n offset(limit)\nend\nself\n"}},{"id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","name":"max","doc":"Adds `MAX` to the current query.","summary":"

Adds MAX to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"max","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"max = \"MAX(#{field})\"\nif name.nil?\nelse\n max = max + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? max : \"#{@select}, #{max}\"\nself\n"}},{"id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","name":"min","doc":"Adds `MIN` to the current query.","summary":"

Adds MIN to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"min","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"min = \"MIN(#{field})\"\nif name.nil?\nelse\n min = min + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? min : \"#{@select}, #{min}\"\nself\n"}},{"id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":314,"url":null},"def":{"name":"not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"AND\")"}},{"id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":291,"url":null},"def":{"name":"not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"AND\")\nself\n"}},{"id":"not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"not_like(field:FieldType,value):QueryBuilder-instance-method","name":"not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":335,"url":null},"def":{"name":"not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"AND\")"}},{"id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":267,"url":null},"def":{"name":"not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"AND\")"}},{"id":"offset(offset):QueryBuilder-instance-method","html_id":"offset(offset):QueryBuilder-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"args_string":"(offset) : QueryBuilder","args_html":"(offset) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":363,"url":null},"def":{"name":"offset","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@offset = add_arg(offset)\nself\n"}},{"id":"offset:String-instance-method","html_id":"offset:String-instance-method","name":"offset","doc":"Returns `offset` value. Returns empty string if no offset has been defined.\n\n```\nputs builder.offset unless builder.offset.blank? # or .empty?\n```","summary":"

Returns #offset value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":373,"url":null},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset"}},{"id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"optimize\ntable(table)\n"}},{"id":"optimize:QueryBuilder-instance-method","html_id":"optimize:QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :optimize\nself\n"}},{"id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":310,"url":null},"def":{"name":"or_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"\", \"OR\")"}},{"id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":286,"url":null},"def":{"name":"or_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"\", \"OR\")\nself\n"}},{"id":"or_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":331,"url":null},"def":{"name":"or_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"\", \"OR\")"}},{"id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":318,"url":null},"def":{"name":"or_not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"OR\")"}},{"id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":296,"url":null},"def":{"name":"or_not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"OR\")\nself\n"}},{"id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":339,"url":null},"def":{"name":"or_not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"OR\")"}},{"id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":271,"url":null},"def":{"name":"or_not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"OR\")"}},{"id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":263,"url":null},"def":{"name":"or_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"\", \"OR\")"}},{"id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","html_id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","name":"order_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"args_string":"(field : FieldType, dir = nil) : QueryBuilder","args_html":"(field : FieldType, dir = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":384,"url":null},"def":{"name":"order_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"field = field.to_s\norder_by = if dir.nil?\n ( (field.includes?(\" \")) || (field == \"rand()\")) ? field : \"#{field} ASC\"\nelse\n \"#{field} #{dir.to_s.upcase}\"\nend\n@order_by = @order_by + (@order_by.empty? ? order_by : \", #{order_by}\")\nself\n"}},{"id":"paginate(per_page,page):QueryBuilder-instance-method","html_id":"paginate(per_page,page):QueryBuilder-instance-method","name":"paginate","doc":"Sets `offset` and `limit` to get pagination-compatible results.","summary":"

Sets #offset and #limit to get pagination-compatible results.

","abstract":false,"args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"args_string":"(per_page, page) : QueryBuilder","args_html":"(per_page, page) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":378,"url":null},"def":{"name":"paginate","args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@limit = add_arg(per_page)\n@offset = add_arg(((page > 0 ? page : 1) - 1) * per_page)\nself\n"}},{"id":"ph(position:Int):String-instance-method","html_id":"ph(position:Int):String-instance-method","name":"ph","doc":"Adds placeholder for a SQL argument.","summary":"

Adds placeholder for a SQL argument.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int) : String","args_html":"(position : Int) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":44,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@placeholder"}},{"id":"query(&):QueryBuilder-instance-method","html_id":"query(&):QueryBuilder-instance-method","name":"query","doc":"Generates a raw query.\n> Be careful, you have to manage arguments and quotes.\n\nExample:\n\n```\nputs builder.query { \"\n SELECT * FROM tests\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n LIMIT 1\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\nLIMIT 1\n```","summary":"

Generates a raw query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":284,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :query\n@query = \" #{with QueryBuilderScope.new(self) yield} \"\nself\n"}},{"id":"query_count:Int-instance-method","html_id":"query_count:Int-instance-method","name":"query_count","doc":"Returns number of queries made by the current instance.","summary":"

Returns number of queries made by the current instance.

","abstract":false,"args":[],"args_string":" : Int","args_html":" : Int","location":{"filename":"src/query_builder/builder.cr","line_number":310,"url":null},"def":{"name":"query_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int","visibility":"Public","body":"@query_count"}},{"id":"query_method:Symbol?-instance-method","html_id":"query_method:Symbol?-instance-method","name":"query_method","doc":"Returns the query method.","summary":"

Returns the query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":305,"url":null},"def":{"name":"query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@query_method"}},{"id":"quote(field:FieldType):String-instance-method","html_id":"quote(field:FieldType):String-instance-method","name":"quote","doc":"Wraps *field* with quotes (`QUOTE`).","summary":"

Wraps field with quotes (QUOTE).

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":39,"url":null},"def":{"name":"quote","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"\"#{QUOTE}#{field}#{QUOTE}\""}},{"id":"repair:QueryBuilder-instance-method","html_id":"repair:QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :repair\nself\n"}},{"id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"repair\ntable(table)\n"}},{"id":"reset_query-instance-method","html_id":"reset_query-instance-method","name":"reset_query","doc":"Resets current query.","summary":"

Resets current query.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"reset_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@query_method = nil\n@query = \"\"\n@data_kv = \"\"\n@data = nil\n@options = nil\n@returning = nil\n@args = [] of DBValue\n@select = \"*\"\n@table = \"\"\n@join = \"\"\n@where = \"\"\n@group_by = \"\"\n@having = \"\"\n@order_by = \"\"\n@limit = \"\"\n@offset = \"\"\nnil\n"}},{"id":"returning(*name:FieldType):QueryBuilder-instance-method","html_id":"returning(*name:FieldType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":450,"url":null},"def":{"name":"returning","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.returning(name)"}},{"id":"returning:String?-instance-method","html_id":"returning:String?-instance-method","name":"returning","doc":"Returns the SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

Returns the SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[],"args_string":" : String?","args_html":" : String?","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":456,"url":null},"def":{"name":"returning","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String | ::Nil","visibility":"Public","body":"@returning"}},{"id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":432,"url":null},"def":{"name":"returning","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if query_method == (:insert)\nelse\n raise(DBX::Error.new(\"\\\"returning\\\" method SHOULD be used only with \\\"insert\\\" statement.\"))\nend\n_fields = _build_selected_fields(fields)\n@returning = if @returning.nil? || ((@returning.not_nil!.compare(\"*\")) == 0)\n _fields\nelse\n \"#{@returning}, #{_fields}\"\nend\nself\n"}},{"id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_join","doc":"Adds `RIGHT JOIN` to the current query.","summary":"

Adds RIGHT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT\")"}},{"id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_outer_join","doc":"Adds `RIGHT OUTER JOIN` to the current query.","summary":"

Adds RIGHT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT OUTER\")"}},{"id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":136,"url":null},"def":{"name":"select","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"_fields = _build_selected_fields(fields)\n@select = (@select.compare(\"*\")) == 0 ? _fields : \"#{@select}, #{_fields}\"\nself\n"}},{"id":"select:String-instance-method","html_id":"select:String-instance-method","name":"select","doc":"Returns selected field(s). Default is `*`.\n\n```\nputs builder.select\n```","summary":"

Returns selected field(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":152,"url":null},"def":{"name":"select","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@select"}},{"id":"select(*name:FieldType):QueryBuilder-instance-method","html_id":"select(*name:FieldType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":143,"url":null},"def":{"name":"select","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.select(name)"}},{"id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","name":"sum","doc":"Adds `SUM` to the current query.","summary":"

Adds SUM to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"sum","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"sum = \"SUM(#{field})\"\nif name.nil?\nelse\n sum = sum + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? sum : \"#{@select}, #{sum}\"\nself\n"}},{"id":"table(&):QueryBuilder-instance-method","html_id":"table(&):QueryBuilder-instance-method","name":"table","doc":"Defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":97,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"table(*name:FieldType):QueryBuilder-instance-method","html_id":"table(*name:FieldType):QueryBuilder-instance-method","name":"table","doc":"Targets tables defined by variadic arguments.\n\n```\nbuilder.table(:table1, :table2)\n```","summary":"

Targets tables defined by variadic arguments.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":79,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"table(name)"}},{"id":"table:String-instance-method","html_id":"table:String-instance-method","name":"table","doc":"Returns table name(s). Returns empty string if no table has been defined.\n\n```\nputs builder.table unless builder.table.blank? # or .empty?\n```","summary":"

Returns table name(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":107,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@table"}},{"id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"table","doc":"Targets one or more tables.","summary":"

Targets one or more tables.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"args_string":"(name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":68,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = name.is_a?(FieldsType) ? name.join(\", \") : name.to_s\nself\n"}},{"id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","html_id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","name":"to_data_h","doc":"Converts `NamedTuple` to `DataHashType`.","summary":"

Converts NamedTuple to DataHashType.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : DataHashType","args_html":"(data : Hash | NamedTuple) : DataHashType","location":{"filename":"src/query_builder/builder.cr","line_number":23,"url":null},"def":{"name":"to_data_h","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DataHashType","visibility":"Public","body":"h = DataHashType.new\ndata.each do |k, v|\n h[k] = v\nend\nh\n"}},{"id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":137,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :update\nif data\nelse\n raise(Error.new(\"No data to update\"))\nend\n@data_kv = add_args_and_kv_from_data(to_data_h(data))\nself\n"}},{"id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":144,"url":null},"def":{"name":"update","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\ntable(table)\n"}},{"id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","args_html":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":149,"url":null},"def":{"name":"update","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\n@query_method = :update_one\nself.where(pk_name, pk_value)\n"}},{"id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","name":"where","doc":"Where clause.","summary":"

Where clause.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":224,"url":null},"def":{"name":"where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where = if @operators.includes?(op_or_val.to_s)\n \" #{type}#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \" #{type}#{field} = #{add_arg(op_or_val)}\"\nend\n@where = @where + (@where.empty? ? where : \" #{and_or}#{where}\")\nself\n"}},{"id":"where(&):QueryBuilder-instance-method","html_id":"where(&):QueryBuilder-instance-method","name":"where","doc":"Adds a raw `where` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").where { \"\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\n```","summary":"

Adds a raw #where to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":258,"url":null},"def":{"name":"where","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilder/ArgsType","path":"DBX/QueryBuilder/ArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::ArgsType","name":"ArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Argument(s) for SQL query.","summary":"

Argument(s) for SQL query.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DataHashType","path":"DBX/QueryBuilder/DataHashType.html","kind":"alias","full_name":"DBX::QueryBuilder::DataHashType","name":"DataHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type of the data `Hash`,\nused as a KV container for insert and update.","summary":"

The type of the data Hash, used as a KV container for insert and update.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DBValue","path":"DBX/QueryBuilder/DBValue.html","kind":"alias","full_name":"DBX::QueryBuilder::DBValue","name":"DBValue","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"DB Value.","summary":"

DB Value.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldsType","path":"DBX/QueryBuilder/FieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldsType","name":"FieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol))","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for several fields contained in an `Enumerable` (e.g: `Array` or `Tuple`).","summary":"

The type for several fields contained in an Enumerable (e.g: Array or Tuple).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldType","path":"DBX/QueryBuilder/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Field type.","summary":"

Field type.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/OneOrMoreFieldsType","path":"DBX/QueryBuilder/OneOrMoreFieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::OneOrMoreFieldsType","name":"OneOrMoreFieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":18,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol)","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for one or more fields.","summary":"

The type for one or more fields.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/SQLandArgsType","path":"DBX/QueryBuilder/SQLandArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::SQLandArgsType","name":"SQLandArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Tuple(String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil))","aliased_html":"{String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The return type of `build` method.","summary":"

The return type of build method.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/QueryBuilderScope","path":"DBX/QueryBuilderScope.html","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope","abstract":false,"superclass":{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"dbx/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/scope.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Handy `QueryBuilder` scope used into `Block`.","summary":"

Handy QueryBuilder scope used into Block.

","class_methods":[],"constructors":[{"id":"new(builder:QueryBuilder)-class-method","html_id":"new(builder:QueryBuilder)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"args_string":"(builder : QueryBuilder)","args_html":"(builder : QueryBuilder)","location":{"filename":"src/query_builder/scope.cr","line_number":13,"url":null},"def":{"name":"new","args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(builder)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"arg(value):String-instance-method","html_id":"arg(value):String-instance-method","name":"arg","doc":"Same as `QueryBuilder#add_arg`","summary":"

Same as QueryBuilder#add_arg

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/scope.cr","line_number":17,"url":null},"def":{"name":"arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.add_arg(value)"}},{"id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","html_id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"args_string":"(field : FieldType, io : IO::Memory) : IO::Memory","args_html":"(field : FieldType, io : IO::Memory) : IO::Memory","location":{"filename":"src/query_builder/scope.cr","line_number":22,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"IO::Memory","visibility":"Public","body":"@builder.quote(field, io)"}},{"id":"q(field:FieldType):String-instance-method","html_id":"q(field:FieldType):String-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/scope.cr","line_number":27,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.quote(field)"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilderScope/FieldType","path":"DBX/QueryBuilderScope/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilderScope::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/scope.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilderScope","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}]}} \ No newline at end of file +{"repository_name":"dbx","body":"# :sparkles: DBX\n\n[![CI Status](https://github.com/Nicolab/crystal-dbx/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-dbx/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-dbx.svg)](https://github.com/Nicolab/crystal-dbx/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-dbx/)\n\n* DB connections manager\n* Query builder\n* ORM (alpha)\n\nDBX is a [Crystal lang](https://crystal-lang.org) module to query the database, built on top of [crystal-db](https://github.com/crystal-lang/crystal-db) (common API for DB drivers).\n\nDBX is designed in a decoupled way to embed only the necessary features (multi-connections manager, query builder, query executor and ORM).\n\n## Documentation\n\n* šŸš€ [Guide](/guide/README.md)\n* šŸ“˜ [API doc](https://nicolab.github.io/crystal-dbx/)\n* :bookmark_tabs: [Spec tests](https://github.com/Nicolab/crystal-dbx/tree/master/spec)\n\n## Contributing\n\n1. Fork it ().\n2. Create your feature branch (`git checkout -b my-new-feature`).\n3. See [Development](#Development).\n4. Commit your changes (`git commit -am 'Add some feature'`).\n5. Push to the branch (`git push origin my-new-feature`).\n6. Create a new Pull Request.\n\n### Development\n\n1. You only need Git, Docker and Docker-compose installed on your machine.\n2. Clone this repo and run `./scripts/prepare`.\n3. Run first `docker-compose up`,\n 1. then enter to container `docker-compose exec test_pg bash` (or `test_sqlite` service),\n 2. into the container `just dev-spec`.\n4. Check the project before committing or pushing, from the host: `./scripts/check`\n\nIt's just Docker and docker-compose, you can directly type all the commands Docker and docker-compose.\n\nāœØ Example:\n\n_Terminal 1_\n\n```sh\n# Start the dev stack\ndocker-compose up\n```\n\n_Terminal 2_\n\n```sh\n# enter in the test_pg container\ndocker-compose exec test_pg bash\n\n# then in the test_pg container\ncrystal run ./src/app.cr\n\n# or with a recipe (helper)\njust dev-spec # <= auto reload when the code change\n\n# recipe list\njust --list\n```\n\nAlso, quickly:\n\n* `docker-compose run --rm test_pg crystal spec`\n* or `docker-compose run --rm test_pg just dev-spec`\n* when you are done: `docker-compose down --remove-orphans`\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-dbx/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n* [Nicolas Talle (@Nicolab)](https://github.com/Nicolab) - Creator and maintainer.\n* Thanks to [@ilourt](https://github.com/ilourt) for the feedbacks and thoughts.\n* This project is useful to you? [Sponsor the developer](https://github.com/sponsors/Nicolab).\n","program":{"html_id":"dbx/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"dbx","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX","path":"DBX.html","kind":"module","full_name":"DBX","name":"DBX","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":60,"url":null},{"filename":"src/query_builder/builder.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":8,"url":null},{"filename":"src/query_builder/executor.cr","line_number":8,"url":null},{"filename":"src/query_builder/scope.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-dbx/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"DBX is a helper to handle multi DBs using the compatible drivers\nwith the common `crystal-db` module.\n\nExample with PostgreSQL:\n\n```\n# Connection URI / DSL https://www.postgresql.org/docs/current/libpq-connect.html#h5o-9\ndb = DBX.open(\"app\", \"postgres://...\", true)\n\npp DBX.db?(\"app\") ? \"defined\" : \"not defined\"\n\ndb.query \"select id, created_at, email from users\" do |rs|\n rs.each do\n id = rs.read(Int32)\n created_at = rs.read(Time)\n email = rs.read(String)\n puts \"##{id}: #{email} #{created_at}\"\n end\nend\n\n# Closes all connections of this DB connection pool and remove this DB connection pool.\nDBX.destroy(\"app\")\n```\n\nModel:\n\n```\nclass User\n include DBX::ORM::DSL\n\n field lang : String\n\n @[JSON::Field(key: \"firstName\")]\n field first_name : String?\nend\n\ndb = DBX.open \"app\", App.cfg.db_uri\n\nuser = User.from_rs(db.query(\"SELECT id, lang, first_name FROM users\"))\npp user.to_json\n\nuser = User.from_json \"{\\\"lang\\\":\\\"fr\\\",\\\"firstName\\\":\\\"Nico\\\"}\"\npp user\n```\n\nSee also `DBX::ORM` for a more advanced model system and query builder.\n\nResources:\n- https://crystal-lang.github.io/crystal-db/api/index.html\n- https://github.com/Nicolab/crystal-dbx/tree/master/guide","summary":"

DBX is a helper to handle multi DBs using the compatible drivers with the common crystal-db module.

","class_methods":[{"id":"db(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"db(name:String,uri:String,strict=false):DB::Database-class-method","name":"db","doc":"Same as `.open`.","summary":"

Same as .open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":92,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"self.open(name, uri, strict)"}},{"id":"db(name:String):DB::Database-class-method","html_id":"db(name:String):DB::Database-class-method","name":"db","doc":"Uses a given DB connection pool.","summary":"

Uses a given DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Database","args_html":"(name : String) : DB::Database","location":{"filename":"src/dbx.cr","line_number":87,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"@@dbs[name]"}},{"id":"db?(name:String):Bool-class-method","html_id":"db?(name:String):Bool-class-method","name":"db?","doc":"Checks that a DB connection pool exists.","summary":"

Checks that a DB connection pool exists.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Bool","args_html":"(name : String) : Bool","location":{"filename":"src/dbx.cr","line_number":82,"url":null},"def":{"name":"db?","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@@dbs.has_key?(name)"}},{"id":"dbs:DBHashType-class-method","html_id":"dbs:DBHashType-class-method","name":"dbs","doc":"Returns all `DB::Database` instances.","summary":"

Returns all DB::Database instances.

","abstract":false,"args":[],"args_string":" : DBHashType","args_html":" : DBHashType","location":{"filename":"src/dbx.cr","line_number":77,"url":null},"def":{"name":"dbs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBHashType","visibility":"Public","body":"@@dbs"}},{"id":"destroy(name:String)-class-method","html_id":"destroy(name:String)-class-method","name":"destroy","doc":"Closes all connections of the DB connection pool *name*\nand remove the *name* DB connection pool.","summary":"

Closes all connections of the DB connection pool name and remove the name DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String)","args_html":"(name : String)","location":{"filename":"src/dbx.cr","line_number":112,"url":null},"def":{"name":"destroy","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@dbs.has_key?(name)\n begin\n (self.db(name)).close\n rescue e : Exception\n puts(\"\\nšŸ‘» DBX.destroy: error caught when closing:\")\n pp(e)\n end\n @@dbs.delete(name)\nend"}},{"id":"destroy:Tuple(Int32,Int32)-class-method","html_id":"destroy:Tuple(Int32,Int32)-class-method","name":"destroy","doc":"Destroy all DB connection pool and and their connections.","summary":"

Destroy all DB connection pool and and their connections.

","abstract":false,"args":[],"args_string":" : Tuple(Int32, Int32)","args_html":" : Tuple(Int32, Int32)","location":{"filename":"src/dbx.cr","line_number":125,"url":null},"def":{"name":"destroy","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple(Int32, Int32)","visibility":"Public","body":"size = @@dbs.size\n@@dbs.each_key do |name|\n self.destroy(name)\nend\n{@@dbs.size, size}\n"}},{"id":"open(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"open(name:String,uri:String,strict=false):DB::Database-class-method","name":"open","doc":"Ensures only once DB connection pool by *name* is open.\nIf the DB connection pool *name* is already initialized, it is returned.\nRaises an error if *strict* is *true* and the DB connection pool *name* is\nalready opened.","summary":"

Ensures only once DB connection pool by name is open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":100,"url":null},"def":{"name":"open","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"if @@dbs.has_key?(name)\n if strict\n else\n return @@dbs[name]\n end\n raise(\"'#{name}' DB connection pool is already opened\")\nend\n@@dbs[name] = DB.open(uri)\n"}},{"id":"pool_open_connections(name:String):Int32-class-method","html_id":"pool_open_connections(name:String):Int32-class-method","name":"pool_open_connections","doc":"Gets the number of the connections opened in the pool of *name*.","summary":"

Gets the number of the connections opened in the pool of name.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Int32","args_html":"(name : String) : Int32","location":{"filename":"src/dbx.cr","line_number":142,"url":null},"def":{"name":"pool_open_connections","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"pool_stats = self.pool_stats(name)\nif pool_stats\nelse\n return 0\nend\npool_stats.open_connections\n"}},{"id":"pool_stats(name:String):DB::Pool::Stats?-class-method","html_id":"pool_stats(name:String):DB::Pool::Stats?-class-method","name":"pool_stats","doc":"Pool stats\nhttps://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html","summary":"

Pool stats https://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Pool::Stats?","args_html":"(name : String) : DB::Pool::Stats?","location":{"filename":"src/dbx.cr","line_number":137,"url":null},"def":{"name":"pool_stats","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Pool::Stats | ::Nil","visibility":"Public","body":"if self.db?(name)\n (self.db(name)).pool.stats\nend"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"around_query_or_exec(&block)-macro","html_id":"around_query_or_exec(&block)-macro","name":"around_query_or_exec","doc":"This macro allows injecting code to be run before and after the execution\nof the request. It should return the yielded value. It must be called with 1\nblock argument that will be used to pass the `args : Enumerable`.\nThis macro should be called at the top level, not from a method.\n\n> Be careful of the performance penalty that each hook may cause,\n be aware that your code will be executed at each query and exec.\n\n```\nDBX.around_query_or_exec do |args|\n puts \"before\"\n res = yield\n puts \"after\"\n\n puts res.class\n puts \"exec\" if res.is_a?(DB::ExecResult)\n puts \"query\" if res.is_a?(DB::ResultSet)\n\n puts \"with args:\"\n pp args\n\n res\nend\n```\n\nExample to measure query execution time:\n\n```\nDBX.around_query_or_exec do |args|\n start = Time.monotonic\n res = yield\n elapsed_time = Time.monotonic - start\n\n puts \"Query execution time: #{elapsed_time}\"\n res\nend\n```","summary":"

This macro allows injecting code to be run before and after the execution of the request.

","abstract":false,"args":[],"args_string":"(&block)","location":{"filename":"src/dbx.cr","line_number":185,"url":null},"def":{"name":"around_query_or_exec","args":[],"double_splat":null,"splat_index":null,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"visibility":"Public","body":" class ::DB::Statement\n def_around_query_or_exec do |args|\n \n{{ block.body }}\n\n \nend\n \nend\n \n"}}],"types":[{"html_id":"dbx/DBX/Adapter","path":"DBX/Adapter.html","kind":"module","full_name":"DBX::Adapter","name":"Adapter","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/adapter.cr","line_number":11,"url":null},{"filename":"src/adapter/pg.cr","line_number":12,"url":null},{"filename":"src/adapter/sqlite.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DB adapter(s) used by `DBX::QueryBuilder` and `DBX::ORM`.","summary":"

DB adapter(s) used by DBX::QueryBuilder and DBX::ORM.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"inject_pg-macro","html_id":"inject_pg-macro","name":"inject_pg","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/pg.cr","line_number":14,"url":null},"def":{"name":"inject_pg","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::PostgreSQL\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}},{"id":"inject_sqlite-macro","html_id":"inject_sqlite-macro","name":"inject_sqlite","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/sqlite.cr","line_number":14,"url":null},"def":{"name":"inject_sqlite","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::SQLite\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}}],"types":[{"html_id":"dbx/DBX/Adapter/Base","path":"DBX/Adapter/Base.html","kind":"class","full_name":"DBX::Adapter::Base","name":"Base","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/adapter.cr","line_number":13,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"}],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"Base adapter.","summary":"

Base adapter.

","class_methods":[{"id":"builder_class:QueryBuilder.class-class-method","html_id":"builder_class:QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class.","summary":"

Returns query builder class.

","abstract":false,"args":[],"args_string":" : QueryBuilder.class","args_html":" : QueryBuilder.class","location":{"filename":"src/adapter/adapter.cr","line_number":34,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder.class","visibility":"Public","body":"raise(NotImplementedError.new(\"'#{self}' model MUST define '#{self}.builder_class' method.\"))"}},{"id":"new_builder:QueryBuilder-class-method","html_id":"new_builder:QueryBuilder-class-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":29,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"constructors":[{"id":"new(db:DB::Database)-class-method","html_id":"new(db:DB::Database)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"args_string":"(db : DB::Database)","args_html":"(db : DB::Database)","location":{"filename":"src/adapter/adapter.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(db)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":true,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/adapter.cr","line_number":42,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"db:DB::Database-instance-method","html_id":"db:DB::Database-instance-method","name":"db","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/adapter/adapter.cr","line_number":19,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@db"}},{"id":"new_builder:QueryBuilder-instance-method","html_id":"new_builder:QueryBuilder-instance-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":24,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","path":"DBX/Adapter/PGQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":58,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for PostgreSQL.\n:inherit:","summary":"

QueryBuilder for PostgreSQL.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"ph(position:Int)-instance-method","html_id":"ph(position:Int)-instance-method","name":"ph","doc":"Adds placeholder specific to PostgreSQL.\nAdds placeholder for a SQL argument.","summary":"

Adds placeholder specific to PostgreSQL.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int)","args_html":"(position : Int)","location":{"filename":"src/adapter/pg.cr","line_number":65,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"#{@placeholder}#{position}\""}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PostgreSQL","path":"DBX/Adapter/PostgreSQL.html","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"PostgreSQL adapter","summary":"

PostgreSQL adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.\n> To get recorded data, PostgreSQL adapter use `RETURNING` SQL statement.\n *pk_name* and *pk_type* are useless and ignored,\n thanks PostgreSQL `RETURNING` that makes it simpler and more efficient :)","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/pg.cr","line_number":37,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create\\\" only, without other statement except the table. \\\"Test.create\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\n((query.insert(data)).returning(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/PostgreSQL/QueryBuilder","path":"DBX/Adapter/PostgreSQL/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::PostgreSQL::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/pg.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::PGQueryBuilder","aliased_html":"DBX::Adapter::PGQueryBuilder","const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLite","path":"DBX/Adapter/SQLite.html","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"SQLite adapter","summary":"

SQLite adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/sqlite.cr","line_number":34,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create!\\\" only, without other statement except the table. \\\"Test.create!\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\ntable_name = query.builder.table.gsub(\"\\\"\", \"\")\nlast_id = (query.insert(data)).exec!.last_insert_id\nif last_id.nil?\n raise(DB::NoResultsError.new(\"Cannot create\"))\nend\n(((query.table(table_name)).find(pk_name, last_id)).select(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/SQLite/QueryBuilder","path":"DBX/Adapter/SQLite/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::SQLite::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::SQLiteQueryBuilder","aliased_html":"DBX::Adapter::SQLiteQueryBuilder","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","path":"DBX/Adapter/SQLiteQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":69,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for SQLite.\n:inherit:","summary":"

QueryBuilder for SQLite.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/DBHashType","path":"DBX/DBHashType.html","kind":"alias","full_name":"DBX::DBHashType","name":"DBHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":62,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, DB::Database)","aliased_html":"Hash(String, DB::Database)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/Error","path":"DBX/Error.html","kind":"class","full_name":"DBX::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":65,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/Model/Error","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when an error occurred, related with `DB` or `DBX`.","summary":"

Raised when an error occurred, related with DB or DBX.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/NotSupportedError","path":"DBX/NotSupportedError.html","kind":"class","full_name":"DBX::NotSupportedError","name":"NotSupportedError","abstract":false,"superclass":{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},"ancestors":[{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":71,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when a method is not supported.\n\nThis can be used either to stub out method bodies,\nor when the method is not supported on the current adapter.","summary":"

Raised when a method is not supported.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM","path":"DBX/ORM.html","kind":"module","full_name":"DBX::ORM","name":"ORM","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model.cr","line_number":8,"url":null},{"filename":"src/orm/model_mixin.cr","line_number":8,"url":null},{"filename":"src/orm/model_query.cr","line_number":8,"url":null},{"filename":"src/orm/orm.cr","line_number":18,"url":null},{"filename":"src/orm/schema/schema.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DBX ORM (Object-Relational Mapping).","summary":"

DBX ORM (Object-Relational Mapping).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model","path":"DBX/ORM/Model.html","kind":"class","full_name":"DBX::ORM::Model","name":"Model","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":48,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Base class for all models.\n\nExample, creation of a model for a table `users`:\n\n```\nclass User < DBX::ORM::Model\n adapter :pg\n\n class Schema # < DBX::ORM::Schema#(User)\n field id : Int64?\n field name : String\n field about : String\n field age : Int32\n end\nend\n```\n\nCustomize `ModelQuery` used by `User` model:\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # Custom select\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Base class for all models.

","class_methods":[{"id":"connection:String-class-method","html_id":"connection:String-class-method","name":"connection","doc":"DB connection name used by this `Model` instance.","summary":"

DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/model.cr","line_number":176,"url":null},"def":{"name":"connection","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@conn_name"}},{"id":"db:DB::Database-class-method","html_id":"db:DB::Database-class-method","name":"db","doc":"Returns DB connection name used by this `Model` instance.","summary":"

Returns DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/orm/model.cr","line_number":181,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"DBX.db(connection)"}},{"id":"models-class-method","html_id":"models-class-method","name":"models","doc":"Returns array of all non-abstract subclasses of *DBX::ORM::Model.\n\n```\nDBX::ORM::Model.models # => [Contact, Address, User]\n```","summary":"

Returns array of all non-abstract subclasses of *DBX::ORM::Model.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model.cr","line_number":190,"url":null},"def":{"name":"models","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% models = @type.all_subclasses.select do |m|\n !m.abstract?\nend %}\n {% if !models.empty? %}\n [\n {% for model in models %}\n ::{{ model.name }},\n {% end %}\n ]\n {% else %}\n [] of ::DBX::ORM::Model.class\n {% end %}\n {% end %}"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model/Error","path":"DBX/ORM/Model/Error.html","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":53,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Model","kind":"class","full_name":"DBX::ORM::Model","name":"Model"},"doc":"Model error.","summary":"

Model error.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/ModelMixin","path":"DBX/ORM/ModelMixin.html","kind":"module","full_name":"DBX::ORM::ModelMixin(Model, ModelQuery)","name":"ModelMixin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model_mixin.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Mixin for `Model` class.\n> Automatically injected into the models.","summary":"

Mixin for Model class.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","html_id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","name":"create!","doc":"Creates a new resource and returns.","summary":"

Creates a new resource and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","args_html":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","location":{"filename":"src/orm/model_mixin.cr","line_number":33,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Model::Schema","visibility":"Public","body":"query.create!(data, returning: returning)"}},{"id":"delete(pk_value):ModelQuery-instance-method","html_id":"delete(pk_value):ModelQuery-instance-method","name":"delete","doc":"Deletes one resource by its primary key.","summary":"

Deletes one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":56,"url":null},"def":{"name":"delete","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete(Model.pk_name, pk_value)"}},{"id":"delete:ModelQuery-instance-method","html_id":"delete:ModelQuery-instance-method","name":"delete","doc":"Deletes one or more resources.","summary":"

Deletes one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":51,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete"}},{"id":"find(pk_value):ModelQuery-instance-method","html_id":"find(pk_value):ModelQuery-instance-method","name":"find","doc":"Find one resource by its primary key.","summary":"

Find one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":23,"url":null},"def":{"name":"find","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find(\"#{self.table_name}.#{Model.pk_name}\", pk_value)"}},{"id":"find:ModelQuery-instance-method","html_id":"find:ModelQuery-instance-method","name":"find","doc":"Find one or more resources.","summary":"

Find one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":18,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find"}},{"id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","name":"insert","doc":"Inserts a new resource.","summary":"

Inserts a new resource.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":28,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.insert(data)"}},{"id":"query:ModelQuery-instance-method","html_id":"query:ModelQuery-instance-method","name":"query","doc":"Creates a new `ModelQuery` instance.","summary":"

Creates a new ModelQuery instance.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":13,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"(ModelQuery.new(self.adapter)).table(self.table_name)"}},{"id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Updates one resource by its primary key.","summary":"

Updates one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_value, data : Hash | NamedTuple) : ModelQuery","args_html":"(pk_value, data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":46,"url":null},"def":{"name":"update","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(Model.pk_name, pk_value, data)"}},{"id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Update one or more resources.","summary":"

Update one or more resources.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":41,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(data)"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/ModelQuery","path":"DBX/ORM/ModelQuery.html","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery","abstract":false,"superclass":{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},"ancestors":[{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model_query.cr","line_number":35,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Generic `ModelQuery` class.\n> Automatically injected into the models.\n\nIf you want to customize the queries of a model, you can define\nyou own `ModelQuery` into this model.\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # A custom `select`\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Generic ModelQuery class.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = ModelQuery(Model).allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","html_id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\ntest = Test.create!(data)\nputs test.id\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","args_html":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","location":{"filename":"src/orm/model_query.cr","line_number":129,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"create!(data, as: Model::Schema, returning: returning, pk_name: Model.pk_name, pk_type: Model.pk_type)"}},{"id":"query_all-instance-method","html_id":"query_all-instance-method","name":"query_all","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":152,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"query_one-instance-method","html_id":"query_one-instance-method","name":"query_one","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":140,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"query_one!-instance-method","html_id":"query_one!-instance-method","name":"query_one!","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":146,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}},{"id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"rel","doc":"Refers to the result of a join in a defined `relation` property path.\n\n```\nusers = User\n .find\n .rel(\"groups\")\n .left_join(\"groups\", \"groups.id\", \"users.group_id\")\n .to_a\n```","summary":"

Refers to the result of a join in a defined relation property path.

","abstract":false,"args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":91,"url":null},"def":{"name":"rel","args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"r = Model::Schema.find_relation_from_path(path.to_s)\n@relations << r[:relation]\nselect_all.select_all(r[:model], table_alias)\n"}},{"id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects the relation fields.\nThis method is automatically called by the methods related to the joins with a model class.","summary":"

Selects the relation fields.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":63,"url":null},"def":{"name":"select_all","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if selected_all?(model_class, table_alias)\n return self\nend\nif table_alias\n table_alias = table_alias.to_s\n sql_fields = model_class.schema_class.fields.join(\",\") do |_, field|\n \"#{table_alias}.#{field[:name]}\"\n end\nelse\n sql_fields = model_class.schema_class.sql_fields\nend\nself.select(sql_fields)\n@rel_fields_selected[\"#{model_class}=>#{table_alias}\"] = true\nself\n"}},{"id":"select_all:ModelQuery(Model)-instance-method","html_id":"select_all:ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects all SQL fields.","summary":"

Selects all SQL fields.

","abstract":false,"args":[],"args_string":" : ModelQuery(Model)","args_html":" : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":47,"url":null},"def":{"name":"select_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if @fields_selected\n return self\nend\nself.select(Model::Schema.sql_fields)\n@fields_selected = true\nself\n"}},{"id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","html_id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the relation fields are selected, `false` otherwise.\nSee `select_rel_fields`","summary":"

Returns true if the relation fields are selected, false otherwise.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","location":{"filename":"src/orm/model_query.cr","line_number":57,"url":null},"def":{"name":"selected_all?","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@rel_fields_selected.has_key?(\"#{model_class}=>#{table_alias}\")"}},{"id":"selected_all?:Bool-instance-method","html_id":"selected_all?:Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the model fields are selected, `false` otherwise.\nSee `select_all`","summary":"

Returns true if the model fields are selected, false otherwise.

","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/orm/model_query.cr","line_number":42,"url":null},"def":{"name":"selected_all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@fields_selected"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":188,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Shortcut, same as `query_all`.","summary":"

Shortcut, same as #query_all.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":182,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":177,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o-instance-method","html_id":"to_o-instance-method","name":"to_o","doc":"Shortcut, same as `query_one`.","summary":"

Shortcut, same as #query_one.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":166,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":172,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!-instance-method","html_id":"to_o!-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!`.","summary":"

Shortcut, same as #query_one!.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":160,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema","path":"DBX/ORM/Schema.html","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":14,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"FIELDS","name":"FIELDS","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null},{"id":"RELATIONS","name":"RELATIONS","value":"{} of String => ASTNode","doc":null,"summary":null}],"included_modules":[{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"`Model` Schema.","summary":"

Model Schema.

","class_methods":[{"id":"fields:MetaFieldHash-class-method","html_id":"fields:MetaFieldHash-class-method","name":"fields","doc":"Returns all SQL fields definitions.","summary":"

Returns all SQL fields definitions.

","abstract":false,"args":[],"args_string":" : MetaFieldHash","args_html":" : MetaFieldHash","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"MetaFieldHash","visibility":"Public","body":"@@fields"}},{"id":"from_rs(rs:DB::ResultSet)-class-method","html_id":"from_rs(rs:DB::ResultSet)-class-method","name":"from_rs","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"from_rs","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n objs = Array(self).new\n rs.each do\n objs << (self.new(rs))\n end\n objs\nensure\n rs.close\nend"}},{"id":"sql_fields:String-class-method","html_id":"sql_fields:String-class-method","name":"sql_fields","doc":"Returns the SQL fields of the model separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_fields"}},{"id":"sql_rel_fields:String-class-method","html_id":"sql_rel_fields:String-class-method","name":"sql_rel_fields","doc":"Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_rel_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_rel_fields"}}],"constructors":[{"id":"new(rs:DB::ResultSet)-class-method","html_id":"new(rs:DB::ResultSet)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"new","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"instance = allocate\ninstance.initialize(__set_for_db_serializable: rs)\nif instance.responds_to?(:finalize)\n GC.add_finalizer(instance)\nend\ninstance\n"}},{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"args_string":"(pull : JSON::PullParser)","args_html":"(pull : JSON::PullParser)","location":{"filename":"src/orm/schema/schema.cr","line_number":23,"url":null},"def":{"name":"new","args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_from_json_pull_parser(pull)"}}],"instance_methods":[{"id":"_pk-instance-method","html_id":"_pk-instance-method","name":"_pk","doc":"Same as `_pk` but may return `nil` when the record hasn't been saved\ninstead of raising.","summary":"

Same as #_pk but may return nil when the record hasn't been saved instead of raising.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":40,"url":null},"def":{"name":"_pk","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.id"}},{"id":"_pk!-instance-method","html_id":"_pk!-instance-method","name":"_pk!","doc":"Always returns this record's primary key value, even when the primary key\nisn't named `_pk`.","summary":"

Always returns this record's primary key value, even when the primary key isn't named #_pk.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":32,"url":null},"def":{"name":"_pk!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk.not_nil!"}},{"id":"_ukey-instance-method","html_id":"_ukey-instance-method","name":"_ukey","doc":"Unique (virtual) key used to compare the uniqueness of models.\nBy default this method returns the primary key (`_pk`) value.\n\nThis method avoid to rely directly on the primary key in case there is none in\nthe structure of the SQL table (even if there should always be one).\nUsed in the relation algorithm.\nAlso, can be useful when there is a need to check the uniqueness in other cases.\n\nIf for some reason your model does not have a primary key,\nyou can override this method to return a unique result\nrelated to the fields in your table, for example:\n\n```\n@[DB::Field(ignore: true)]\n@[JSON::Field(ignore: true)]\ndef _ukey\n \"#{self.group_id}.#{self.user_id}\"\nend\n```","summary":"

Unique (virtual) key used to compare the uniqueness of models.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":65,"url":null},"def":{"name":"_ukey","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk"}}],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Schema/MetaField","path":"DBX/ORM/Schema/MetaField.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaField","name":"MetaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":16,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String)","aliased_html":"{name: String, rel_name: String, sql: String, rel_sql: String}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/MetaFieldHash","path":"DBX/ORM/Schema/MetaFieldHash.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaFieldHash","name":"MetaFieldHash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":17,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String))","aliased_html":"Hash(String, {name: String, rel_name: String, sql: String, rel_sql: String})","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/RelationDef","path":"DBX/ORM/Schema/RelationDef.html","kind":"alias","full_name":"DBX::ORM::Schema::RelationDef","name":"RelationDef","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool)","aliased_html":"{name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/SchemaField","path":"DBX/ORM/SchemaField.html","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/field.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"field(name)-macro","html_id":"field(name)-macro","name":"field","doc":"Defines a SQL field.","summary":"

Defines a SQL field.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"args_string":"(name)","location":{"filename":"src/orm/schema/def/field.cr","line_number":10,"url":null},"def":{"name":"field","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if name.is_a?(TypeDeclaration) %}\n {% full_name = \"#{model_class}.#{name.var}\"\nif FIELDS[full_name].nil?\n FIELDS[full_name] = HashLiteral(String, ASTNode).new\nend\nFIELDS[full_name] = {model: model_class, name: name.var, full_name: full_name.id, rel_name: \"__#{model_class}_#{name.var}\", type: name.type, type_class: \"#{name.type.is_a?(Union) ? \"(#{name.type})\".id : name.type}.class\".id, default: name.value || \"nil\".id}\n %}\n\n @{{ name.var }} : {{ name.type }}{% if name.value %} = {{ name.value }}{% end %}\n def {{ name.var }} : {{ name.type }}\n @{{ name.var }}\n end\n\n def {{ name.var }}=(value : {{ name.type }})\n @{{ name.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.field doesn't support \" + name.class_name) %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","path":"DBX/ORM/SchemaInjectFields.html","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/inject_fields.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_fields-macro","html_id":"orm_schema_inject_fields-macro","name":"orm_schema_inject_fields","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_fields.cr","line_number":9,"url":null},"def":{"name":"orm_schema_inject_fields","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" @@fields : MetaFieldHash = MetaFieldHash.new\n @@sql_fields : String = \"\"\n @@sql_rel_fields : String = \"\"\n\n \n# Returns all SQL fields definitions.\n\n def self.fields : MetaFieldHash\n @@fields\n \nend\n\n \n# Returns the SQL fields of the model separated by a comma (table.column, ...).\n\n def self.sql_fields : String\n @@sql_fields\n \nend\n\n \n# Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).\n\n def self.sql_rel_fields : String\n @@sql_rel_fields\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","path":"DBX/ORM/SchemaInjectForFinal.html","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal","abstract":false,"superclass":null,"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"locations":[{"filename":"src/orm/schema/inject_for_final.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_for_final-macro","html_id":"orm_schema_inject_for_final-macro","name":"orm_schema_inject_for_final","doc":"Finish for the final `Schema` class.","summary":"

Finish for the final Schema class.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_for_final.cr","line_number":13,"url":null},"def":{"name":"orm_schema_inject_for_final","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% model_relations = {} of Symbol => ASTNode %}\n\n\n \n{% for path, dec in RELATIONS %}\n {% if model_class == dec[:from_model] %}\n {% model_relations[path] = dec %}\n {% end %}\n {% end %}\n\n\n \n{% consts = @type.constants.map(&.symbolize) %}\n\n \n{% if consts.includes?(:DBValue) %}{% else %}\n alias DBValue = DBX::QueryBuilder::DBValue\n {% end %}\n\n\n \n# Returns model table name.\n\n def self.table_name : String\n model_class.table_name\n \nend\n\n \n# Returns model class.\n\n def self.model_class : \n{{ model_class }}\n.class\n \n{{ model_class }}\n\n \nend\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @@fields[{{ full_name }}] = {\n name: \"{{ dec[:name] }}\",\n rel_name: {{ dec[:rel_name] }},\n sql: \"#{table_name}.{{ dec[:name] }}\",\n rel_sql: \"#{table_name}.{{ dec[:name] }} AS {{ dec[:rel_name].id }}\"\n }\n {% end %}\n {% end %}\n\n\n @@sql_fields : String = self.fields.join(\",\") \n{ |_, f| f[:sql] }\n @@sql_rel_fields : String = self.fields.join(\",\") \n{ |_, f| f[:rel_sql] }\n\n \n# All DB fields of the `\n{{ model_class }}\n` model.\n\n alias FieldsDef = \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type_class] }} },\n {% end %}\n {% end %}\n\n }\n\n \n# --------------------------------------------------------------------------\n\n\n \n# Creates a new `\n{{ model_class }}\n` instance.\n\n \n# > Useful to create (insert) a new entry in the DB.\n\n def initialize(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @{{ dec[:name] }} : {{ dec[:type] }} = {{ dec[:default] }},\n {% end %}\n {% end %}\n\n )\n \nend\n\n \n# Creates a new _strict_ `\n{{ model_class }}\n` instance without using default value.\n\n \n# > Can be populated with data from the DB.\n\n def self.new_strict(\n \n{% args = [] of ASTNode %}\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }} : {{ dec[:type] }},\n {% args << dec[:name] %}\n {% end %}\n {% end %}\n\n )\n \n{{ model_class }}\n::Schema.new(\n{{ args.splat }}\n)\n \nend\n\n private def self.process_next_rel(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n schema : \n{{ model_class }}\n::Schema,\n rel_idx : Int32,\n cols_readed : Int32\n )\n next_rel = relations[rel_idx]\n\n case next_rel[:name]\n \n{% for path, dec in model_relations %}\n {% if model_class == dec[:from_model] %}\n when {{ dec[:name] }}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} : {{ dec[:model_class] }}::Schema? = nil\n\n {% if dec[:has_many] %}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} = schema.{{ dec[:name].id }}.last?\n {% end %}\n\n if rel_schema = {{ dec[:model_class] }}::Schema.from_rs(\n rs,\n relations,\n rel_idx + 1, # move cursor to next rel\n cols_readed,\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }},\n )\n schema.{{ dec[:name].id }} {{ dec[:has_one] ? \"=\".id : \"<<\".id }} rel_schema.as({{ dec[:model_class] }}::Schema)\n end\n {% end %}\n {% end %}\n\n \nelse\n raise DBX::Error.new %(Cannot resolve the relation \"#{next_rel[:model_class]}.#{next_rel[:name]}\")\n \nend\n \nend\n\n \n# Creates an instance from a relation.\n\n def self.from_rs(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n rel_idx : Int32 = 0,\n cols_readed : Int32 = 0,\n last_schema : \n{{ model_class }}\n::Schema? = nil,\n ) : Schema?\n if relations.size == 0\n raise DBX::Error.new \"Bad method call. This method must be called only for a query with relation(s).\"\n \nend\n\n cols_total = rs.column_count\n\n \n{% cols_readed_initial = 0 %}\n\n\n \n# Fix: PG::ResultSet#read returned a String. A (Int64 | Nil) was expected.\n\n \n# Prevent this error when a resource is found without its relation(s) (like a conventional LEFT JOIN).\n\n should_not_read_first_field = false\n\n \n# first iter or try to check with pk for deep iter\n\n if !last_schema || cols_readed == 0 || \n{{ model_class }}\n.pk_name == rs.column_name(cols_readed)\n first_field = rs.read\n should_not_read_first_field = true\n \n{% cols_readed_initial += 1 %}\n\n return nil if first_field.nil?\n \nend\n\n schema = \n{{ model_class }}\n::Schema.new_strict(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: if should_not_read_first_field\n should_not_read_first_field = false\n first_field.as({{ dec[:type] }})\n else\n rs.read({{ dec[:type] }})\n end,\n {% cols_readed_initial += 1 %}\n {% end %}\n {% end %}\n\n )\n\n \n# avoid duplicate for deep iteration(s)\n\n if !last_schema.nil? && last_schema._ukey == schema._ukey\n schema = last_schema\n \nend\n\n cols_readed += \n{{ cols_readed_initial }}\n\n\n if rel_idx + 1 <= relations.size\n self.process_next_rel(rs, relations, schema, rel_idx, cols_readed)\n return schema\n \nend\n\n return schema if cols_total == cols_readed\n schema\n \nend\n\n \n# --------------------------------------------------------------------------\n\n\n def self.fields_def : FieldsDef\n \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type] }} },\n {% end %}\n {% end %}\n\n }\n \nend\n\n def self.relations_def : Hash(String, RelationDef)\n @@relations_def\n \nend\n\n def self.add_relation(path : String | Symbol, dec : RelationDef) : Schema.class\n full_path = \"\n{{ model_class }}\n.#{path}\"\n\n if @@relations_def.has_key?(full_path)\n raise DBX::Error.new %(relation \"#{full_path}\" already defined)\n \nend\n\n @@relations_def[full_path] = dec\n self\n \nend\n\n \n# Lookup the path in relations def.\n\n def self.lookup_relation_def?(path : Symbol | String) : \n{String, RelationDef?}\n model_name = \"#{model_class}\"\n path = path.to_s\n cursor_path = \"#{model_name}.#{path}\"\n\n if rel_found = @@relations_def[cursor_path]?\n return \n{ cursor_path, rel_found }\n \nend\n\n path_a = path.split(\".\")\n\n \n# not found above\n\n return \n{cursor_path, nil} if path_a.size == 1\n\n \n# lookup the rest\n\n cursor_path = \"#{model_name}.#{path_a.first}\"\n path_a.size.times do |i|\n next_part_i = i + 1\n\n if rel_found = @@relations_def[\"#{cursor_path}\"]?\n cursor_path = \"#{rel_found[:model_class]}.#{path_a[next_part_i]}\"\n \nend\n\n \n# if end of search\n\n break rel_found if path_a.size == next_part_i + 1\n \nend\n\n \n{cursor_path, rel_found}\n \nend\n\n \n# Find a relation from its path.\n\n def self.find_relation_from_path(path : String) : \n{\n relation: RelationDef,\n cursor_path: String,\n field: String,\n model: DBX::ORM::Model.class\n }\n raise DBX::Error.new \"Relation path is empty\" if path.empty?\n cursor_path, relation_def = self.lookup_relation_def?(path)\n\n \n# r_model is the rel_model if the path is not deep, ref_model for deep path\n\n unless relation_def && (r_model = relation_def[:model_class])\n parts = path.split('.')\n\n if parts.size > 2\n raise DBX::Error.new %(\n Relation path to long: \"#{path}\".\n The depth of a relationship selection cannot exceed 2 levels (max is \"#{parts[...-1].join(\".\")}\").\n PR is welcome ;-\\)\n )\n \nend\n\n raise DBX::Error.new %(Undefined relation \"#{path}\")\n \nend\n\n parts = path.split('.')\n\n \n# if not deep\n\n if parts.size == 1\n return \n{ relation: relation_def, cursor_path: cursor_path, field: path, model: r_model }\n \nend\n\n ref_model = r_model\n rel_field = parts.last\n\n \n{% i = 0 %}\n\n \n{% cond_start = \"if\".id %}\n\n \n{% for path, dec in RELATIONS %}\n {% i += 1 %}\n {% if i != 1 %}\n {% cond_start = \"elsif\".id %}\n {% end %}\n\n # if the model referant is found\n {{ cond_start }} ref_model == {{ dec[:from_model] }} && {{ dec[:name] }} == rel_field\n # relation model is resolved\n rel_model = {{ dec[:model_class] }}\n\n relation_def = {\n name: {{ dec[:name] }},\n model_class: {{ dec[:model_class] }},\n has_one: {{ dec[:has_one] }},\n has_many: {{ dec[:has_many] }}\n }\n {% end %}\n\n \n{% if i > 0 %}{{ \"end\".id }}{% end %}\n \n# end: cond_start\n\n\n raise DBX::Error.new %(Model not found for relation path: \"#{path}\") unless rel_model\n\n \n{ relation: relation_def, cursor_path: cursor_path, field: rel_field, model: rel_model }\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaRelation","path":"DBX/ORM/SchemaRelation.html","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/relation.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"relation(var_decl,**opt)-macro","html_id":"relation(var_decl,**opt)-macro","name":"relation","doc":"Defines a relation.","summary":"

Defines a relation.

","abstract":false,"args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"args_string":"(var_decl, **opt)","location":{"filename":"src/orm/schema/def/relation.cr","line_number":10,"url":null},"def":{"name":"relation","args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"double_splat":{"name":"opt","doc":null,"default_value":"","external_name":"opt","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if var_decl.is_a?(TypeDeclaration) %}\n {% if var_decl.type.stringify.starts_with?(\"Array\")\n rel_model = var_decl.type.stringify[6...-1].id\n rel_schema_type = \"Array(#{rel_model}::Schema)\".id\n has_one = false\n has_many = true\nelse\n rel_model = var_decl.type\n rel_schema_type = \"#{rel_model}::Schema\".id\n has_one = true\n has_many = false\nend %}\n\n unless {{ var_decl.type }}.is_a?(DBX::ORM::Model.class) || {{ rel_model }}.is_a?(DBX::ORM::Model.class)\n raise \"{{ model_class }}: relation must be a Model class but is a {{ var_decl.type }}\"\n end\n\n {% RELATIONS[\"#{model_class}.#{var_decl.var}\"] = {name: \"#{var_decl.var}\", model_class: rel_model, from_model: model_class, has_one: has_one, has_many: has_many} %}\n\n self.add_relation(\"{{ var_decl.var }}\", {\n name: \"{{ var_decl.var }}\",\n model_class: {{ rel_model }},\n has_one: {{ has_one }},\n has_many: {{ has_many }},\n })\n\n @[JSON::Field(emit_null: false)]\n @[DB::Field(ignore: true)]\n @{{ var_decl.var }} : {{ rel_schema_type }}?\n\n def {{ var_decl.var }} : {{ rel_schema_type }}{% if has_one %}?{% end %}\n {% if has_many %}\n @{{ var_decl.var }} = [] of {{ rel_model }}::Schema unless @{{ var_decl.var }}\n return @{{ var_decl.var }}.not_nil!\n {% end %}\n\n @{{ var_decl.var }}\n end\n\n def {{ var_decl.var }}=(value : {{ rel_schema_type }})\n @{{ var_decl.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.relation doesn't support #{var_decl.class_name}\") %}\n {% end %}\n\n \n"}}],"types":[]}]},{"html_id":"dbx/DBX/Query","path":"DBX/Query.html","kind":"class","full_name":"DBX::Query","name":"Query","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/executor.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/ModelQuery","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query executor.\nSee also: https://crystal-lang.github.io/crystal-db/api/latest/DB/QueryMethods.html","summary":"

Query executor.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"build:Tuple-instance-method","html_id":"build:Tuple-instance-method","name":"build","doc":"Builds current query and returns `sql, args`.\nSee `DBX::QueryBuilder#build` method.","summary":"

Builds current query and returns sql, args.

","abstract":false,"args":[],"args_string":" : Tuple","args_html":" : Tuple","location":{"filename":"src/query_builder/executor.cr","line_number":170,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple","visibility":"Public","body":"@builder.build"}},{"id":"builder:DBX::QueryBuilder-instance-method","html_id":"builder:DBX::QueryBuilder-instance-method","name":"builder","doc":"Returns `DBX::QueryBuilder` instance used in current `Query` instance.","summary":"

Returns DBX::QueryBuilder instance used in current Query instance.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder","args_html":" : DBX::QueryBuilder","location":{"filename":"src/query_builder/executor.cr","line_number":175,"url":null},"def":{"name":"builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder","visibility":"Public","body":"@builder"}},{"id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {String, Int32},\n returning: {:name, :age}\n)\n# => {\"Baby\", 1}\n\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {name: String, age: Int32},\n returning: {:name, :age}\n)\n# => {name: \"Baby\", age: 1}\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/query_builder/executor.cr","line_number":198,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@adapter.create!(self, data, types, returning, pk_name, pk_type)"}},{"id":"exec-instance-method","html_id":"exec-instance-method","name":"exec","doc":":ditto:\nReturns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: Returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":42,"url":null},"def":{"name":"exec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n exec!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"exec!-instance-method","html_id":"exec!-instance-method","name":"exec!","doc":"Executes current built query that is expected to return an `DB::ExecResult`.","summary":"

Executes current built query that is expected to return an DB::ExecResult.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":22,"url":null},"def":{"name":"exec!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_method = @builder.query_method\nsql, args = @builder.build\ner = @db.exec(sql, args: args)\nif (((((query_method == (:insert)) || (query_method == (:update_one))) || (query_method == (:update))) || (query_method == (:delete_one))) || (query_method == (:delete))) && (er.rows_affected == 0)\n raise(DB::NoResultsError.new(\"DB::ExecResult: No rows affected\"))\nend\ner\n"}},{"id":"query-instance-method","html_id":"query-instance-method","name":"query","doc":"Executes current built query that is expected to return one or more results.\n\n```\ntests = [] of Array(String | Int32)\nrs = query.find(:tests).select(:name, :age).query\n\nbegin\n while rs.move_next\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nensure\n rs.close\nend\n```","summary":"

Executes current built query that is expected to return one or more results.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":64,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args)\n"}},{"id":"query(&)-instance-method","html_id":"query(&)-instance-method","name":"query","doc":"Executes current built query and yields a `DB::ResultSet` with the results.\nThe `DB::ResultSet` is closed automatically.\n\n```\ntests = [] of Array(String | Int32)\nquery.find(:tests).select(:name, :age).query do |rs|\n rs.each do\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nend\n```","summary":"

Executes current built query and yields a DB::ResultSet with the results.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":82,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_all(astypes)-instance-method","html_id":"query_all(astypes)-instance-method","name":"query_all","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":88,"url":null},"def":{"name":"query_all","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args, as: types)\n"}},{"id":"query_all(&)-instance-method","html_id":"query_all(&)-instance-method","name":"query_all","doc":"Executes current built query and yields a `DB::ResultSet` positioned\nat the beginning of each row, returning an `Array` of the values of the blocks.","summary":"

Executes current built query and yields a DB::ResultSet positioned at the beginning of each row, returning an Array of the values of the blocks.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":95,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_each(&)-instance-method","html_id":"query_each(&)-instance-method","name":"query_each","doc":"Executes current built query and yields the `DB::ResultSet` once per each row.","summary":"

Executes current built query and yields the DB::ResultSet once per each row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":101,"url":null},"def":{"name":"query_each","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_each(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_one(astypes)-instance-method","html_id":"query_one(astypes)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":114,"url":null},"def":{"name":"query_one","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one!(types)\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one(&)-instance-method","html_id":"query_one(&)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":129,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one! do |rs|\n yield rs\n end\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one!(astypes)-instance-method","html_id":"query_one!(astypes)-instance-method","name":"query_one!","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":107,"url":null},"def":{"name":"query_one!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args, as: types)\n"}},{"id":"query_one!(&)-instance-method","html_id":"query_one!(&)-instance-method","name":"query_one!","doc":"Executes current built query that expects at most a single row and yields\na `DB::ResultSet` positioned at that first row.","summary":"

Executes current built query that expects at most a single row and yields a DB::ResultSet positioned at that first row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":122,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"raw_query(&):Query-instance-method","html_id":"raw_query(&):Query-instance-method","name":"raw_query","doc":"See `DBX::QueryBuilder#query`","summary":"

See DBX::QueryBuilder#query

","abstract":false,"args":[],"args_string":"(&) : Query","args_html":"(&) : Query","location":{"filename":"src/query_builder/executor.cr","line_number":161,"url":null},"def":{"name":"raw_query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"Query","visibility":"Public","body":"@builder.query do\n with QueryBuilderScope.new(@builder) yield\nend\nself\n"}},{"id":"scalar-instance-method","html_id":"scalar-instance-method","name":"scalar","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.\nSo the type MUST be nillable:\n\n```\nquery\n .find(:tests)\n .select(:name)\n .where(:name, \"Terminator\")\n .scalar\n .as(String?)\n# => String | Nil\n```","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":154,"url":null},"def":{"name":"scalar","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n scalar!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"scalar!-instance-method","html_id":"scalar!-instance-method","name":"scalar!","doc":"Executes current built query and returns a single scalar value.","summary":"

Executes current built query and returns a single scalar value.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":136,"url":null},"def":{"name":"scalar!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.scalar(sql, args: args)\n"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as #query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":229,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a(&)-instance-method","html_id":"to_a(&)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(&block)`.","summary":"

Shortcut, same as #query_all(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":234,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all do |rs|\n yield rs\nend"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as #query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":214,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o(&)-instance-method","html_id":"to_o(&)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(&block)`.","summary":"

Shortcut, same as #query_one(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":224,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one do |rs|\n yield rs\nend"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as #query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":209,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!(&)-instance-method","html_id":"to_o!(&)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(&block)`.","summary":"

Shortcut, same as #query_one!(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":219,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one! do |rs|\n yield rs\nend"}}],"macros":[{"id":"method_missing(call)-macro","html_id":"method_missing(call)-macro","name":"method_missing","doc":null,"summary":null,"abstract":false,"args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"args_string":"(call)","location":{"filename":"src/query_builder/executor.cr","line_number":238,"url":null},"def":{"name":"method_missing","args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% if true %}\n {% if block = call.block %}\n # See `DBX::QueryBuilder#{{ call.name }}(&block` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }}) {{ block }}\n self\n end\n {% else %}\n # See `DBX::QueryBuilder#{{ call.name }}` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }})\n self\n end\n {% end %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/QueryBuilder","path":"DBX/QueryBuilder.html","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/builder.cr","line_number":9,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":10,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":9,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":"Quoting character.","summary":"

Quoting character.

"}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder"},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query builder.","summary":"

Query builder.

","class_methods":[],"constructors":[{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Creates a new `QueryBuilder`.","summary":"

Creates a new QueryBuilder.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_arg(value):String-instance-method","html_id":"add_arg(value):String-instance-method","name":"add_arg","doc":"Adds value to *args* and returns the `placeholder`.","summary":"

Adds value to args and returns the placeholder.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":49,"url":null},"def":{"name":"add_arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"if value.is_a?(Symbol)\n value = value.to_s\nend\n@args << value\nph(@args.size)\n"}},{"id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":58,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |_, value|\n add_arg(value)\nend"}},{"id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : Array, sep = ", ") : String","args_html":"(data : Array, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":63,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |value|\n add_arg(value)\nend"}},{"id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_kv_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a combined statement.\nExample: `field1 = $1, field2 = $2, field3 = $3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a combined statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":70,"url":null},"def":{"name":"add_args_and_kv_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |field, value|\n \"#{field} = #{add_arg(value)}\"\nend"}},{"id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":212,"url":null},"def":{"name":"alter","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"alter(command, field, data_type)\ntable(table)\n"}},{"id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(command : String, field : String, data_type = "") : QueryBuilder","args_html":"(command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":206,"url":null},"def":{"name":"alter","args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :alter\n@options = {command: command, field: field, data_type: data_type}\nself\n"}},{"id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"analyze\ntable(table)\n"}},{"id":"analyze:QueryBuilder-instance-method","html_id":"analyze:QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :analyze\nself\n"}},{"id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","name":"avg","doc":"Adds `AVG` to the current query.","summary":"

Adds AVG to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"avg","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"avg = \"AVG(#{field})\"\nif name.nil?\nelse\n avg = avg + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? avg : \"#{@select}, #{avg}\"\nself\n"}},{"id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","name":"between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":301,"url":null},"def":{"name":"between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nelse\n \" #{and_or} #{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nend)\nself\n"}},{"id":"build:SQLandArgsType-instance-method","html_id":"build:SQLandArgsType-instance-method","name":"build","doc":"Builds the current query and returns SQL (string) and arguments (array).\n\n```\nsql, args = builder.build\n```","summary":"

Builds the current query and returns SQL (string) and arguments (array).

","abstract":false,"args":[],"args_string":" : SQLandArgsType","args_html":" : SQLandArgsType","location":{"filename":"src/query_builder/builder.cr","line_number":34,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"SQLandArgsType","visibility":"Public","body":"{% if true %}\n case @query_method\n {% for method in [:find, :insert, :update, :delete, :drop, :alter, :query, :analyze, :check, :checksum, :optimize, :repair] %}\n when :{{ method.id }} then end_query(build_query_{{ method.id }})\n {% end %}\n when :update_one then end_query(build_query_update)\n when :delete_one then end_query(build_query_delete)\n else\n raise Error.new \"Bad QueryBuilder method. #{@query_method}\"\n end\n {% end %}"}},{"id":"check:QueryBuilder-instance-method","html_id":"check:QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :check\nself\n"}},{"id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"check\ntable(table)\n"}},{"id":"checksum:QueryBuilder-instance-method","html_id":"checksum:QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :checksum\nself\n"}},{"id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"checksum\ntable(table)\n"}},{"id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","name":"count","doc":"Adds `COUNT` to the current query.","summary":"

Adds COUNT to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"count","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"count = \"COUNT(#{field})\"\nif name.nil?\nelse\n count = count + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? count : \"#{@select}, #{count}\"\nself\n"}},{"id":"delete:QueryBuilder-instance-method","html_id":"delete:QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":165,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :delete\nself\n"}},{"id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":170,"url":null},"def":{"name":"delete","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\ntable(table)\n"}},{"id":"delete(pk_name,pk_value):QueryBuilder-instance-method","html_id":"delete(pk_name,pk_value):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":175,"url":null},"def":{"name":"delete","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\n@query_method = :delete_one\nself.where(pk_name, pk_value)\n"}},{"id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","html_id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":195,"url":null},"def":{"name":"drop","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"drop(check_exists)\ntable(table)\n"}},{"id":"drop(check_exists=true):QueryBuilder-instance-method","html_id":"drop(check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(check_exists = true) : QueryBuilder","args_html":"(check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":189,"url":null},"def":{"name":"drop","args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :drop\n@options = check_exists\nself\n"}},{"id":"find(pk_name,pk_value):QueryBuilder-instance-method","html_id":"find(pk_name,pk_value):QueryBuilder-instance-method","name":"find","doc":"Finds one resource by its primary key.\n\nSame as:\n\n```\nbuilder.find.where(pk_name, pk_value)\n```","summary":"

Finds one resource by its primary key.

","abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":101,"url":null},"def":{"name":"find","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find.where(pk_name, pk_value)"}},{"id":"find:QueryBuilder-instance-method","html_id":"find:QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":63,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :find\nself\n"}},{"id":"find(&):QueryBuilder-instance-method","html_id":"find(&):QueryBuilder-instance-method","name":"find","doc":"Adds `find` to current query\nand defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Adds #find to current query and defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":88,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\n@table = \"#{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"args_string":"(table_name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table_name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":68,"url":null},"def":{"name":"find","args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\ntable(table_name)\n"}},{"id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_join","doc":"Adds `FULL JOIN` to the current query.","summary":"

Adds FULL JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL\")"}},{"id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_outer_join","doc":"Adds `FULL OUTER JOIN` to the current query.","summary":"

Adds FULL OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL OUTER\")"}},{"id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"group_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"args_string":"(field : OneOrMoreFieldsType) : QueryBuilder","args_html":"(field : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":396,"url":null},"def":{"name":"group_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@group_by = field.is_a?(FieldsType) ? field.join(\", \") : field.to_s\nself\n"}},{"id":"having(&):QueryBuilder-instance-method","html_id":"having(&):QueryBuilder-instance-method","name":"having","doc":"Defines in raw form the SQL statement of `HAVING`.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(:tests).group_by(:payment).having { \"SUM(price) > 40\" }\n```\n\nGenerates:\n\n```\nSELECT * FROM tests GROUP_BY payment HAVING SUM(person) > 40\n```","summary":"

Defines in raw form the SQL statement of HAVING.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":425,"url":null},"def":{"name":"having","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"having","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":402,"url":null},"def":{"name":"having","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = if @operators.includes?(op_or_val.to_s)\n \"#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \"#{field} > #{add_arg(op_or_val)}\"\nend\nself\n"}},{"id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","name":"in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":275,"url":null},"def":{"name":"in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"keys = [] of String\nvalues.each do |val|\n keys << (add_arg(val))\nend\n@where = @where + (if @where.empty?\n \"#{field} #{type}IN (#{keys.join(\", \")})\"\nelse\n \" #{and_or} #{field} #{type}IN (#{keys.join(\", \")})\"\nend)\nself\n"}},{"id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"inner_join","doc":"Adds `INNER JOIN` to the current query.","summary":"

Adds INNER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"inner_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"INNER\")"}},{"id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":119,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :insert\n@data = to_data_h(data)\nself\n"}},{"id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":125,"url":null},"def":{"name":"insert","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"insert(data)\ntable(table)\n"}},{"id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","html_id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","name":"join","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":166,"url":null},"def":{"name":"join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + (if field2.nil?\n \" #{type} JOIN #{table} ON #{field1}\"\nelse\n \" #{type} JOIN #{table} ON #{field1} = #{field2}\"\nend)\nself\n"}},{"id":"join(&):QueryBuilder-instance-method","html_id":"join(&):QueryBuilder-instance-method","name":"join","doc":"Adds a raw `join` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").join { \"\n INNER JOIN T2 ON T1.a = T2.a\n AND T1.b = T2.b\n OR T1.b = #{q(some_value_to_quote)}\n\" }\n .join { \"LEFT JOIN payments p USING (product_id)\" }\n```","summary":"

Adds a raw #join to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":193,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"join:String-instance-method","html_id":"join:String-instance-method","name":"join","doc":"Returns jointure. Returns empty string if no jointure has been defined.\n\n```\nputs builder.join unless builder.join.blank? # or .empty?\n```","summary":"

Returns jointure.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":215,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@join"}},{"id":"last_query:String-instance-method","html_id":"last_query:String-instance-method","name":"last_query","doc":"Returns the last query.","summary":"

Returns the last query.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder.cr","line_number":295,"url":null},"def":{"name":"last_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@last_query"}},{"id":"last_query_method:Symbol?-instance-method","html_id":"last_query_method:Symbol?-instance-method","name":"last_query_method","doc":"Returns the last query method.","summary":"

Returns the last query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":300,"url":null},"def":{"name":"last_query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@last_query_method"}},{"id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_join","doc":"Adds `LEFT JOIN` to the current query.","summary":"

Adds LEFT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT\")"}},{"id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_outer_join","doc":"Adds `LEFT OUTER JOIN` to the current query.","summary":"

Adds LEFT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT OUTER\")"}},{"id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","name":"like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":322,"url":null},"def":{"name":"like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}LIKE #{add_arg(value)}\"\nelse\n \" #{and_or} #{field} #{type}LIKE #{add_arg(value)}\"\nend)\nself\n"}},{"id":"limit:String-instance-method","html_id":"limit:String-instance-method","name":"limit","doc":"Returns `limit` value. Returns empty string if no limit has been defined.\n\n```\nputs builder.limit unless builder.limit.blank? # or .empty?\n```","summary":"

Returns #limit value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":359,"url":null},"def":{"name":"limit","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@limit"}},{"id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","html_id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","name":"limit","doc":null,"summary":null,"abstract":false,"args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"args_string":"(limit, limit_end = nil) : QueryBuilder","args_html":"(limit, limit_end = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":343,"url":null},"def":{"name":"limit","args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if limit_end.nil?\n @limit = add_arg(limit)\nelse\n @limit = add_arg(limit_end)\n offset(limit)\nend\nself\n"}},{"id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","name":"max","doc":"Adds `MAX` to the current query.","summary":"

Adds MAX to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"max","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"max = \"MAX(#{field})\"\nif name.nil?\nelse\n max = max + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? max : \"#{@select}, #{max}\"\nself\n"}},{"id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","name":"min","doc":"Adds `MIN` to the current query.","summary":"

Adds MIN to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"min","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"min = \"MIN(#{field})\"\nif name.nil?\nelse\n min = min + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? min : \"#{@select}, #{min}\"\nself\n"}},{"id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":314,"url":null},"def":{"name":"not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"AND\")"}},{"id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":291,"url":null},"def":{"name":"not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"AND\")\nself\n"}},{"id":"not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"not_like(field:FieldType,value):QueryBuilder-instance-method","name":"not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":335,"url":null},"def":{"name":"not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"AND\")"}},{"id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":267,"url":null},"def":{"name":"not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"AND\")"}},{"id":"offset(offset):QueryBuilder-instance-method","html_id":"offset(offset):QueryBuilder-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"args_string":"(offset) : QueryBuilder","args_html":"(offset) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":363,"url":null},"def":{"name":"offset","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@offset = add_arg(offset)\nself\n"}},{"id":"offset:String-instance-method","html_id":"offset:String-instance-method","name":"offset","doc":"Returns `offset` value. Returns empty string if no offset has been defined.\n\n```\nputs builder.offset unless builder.offset.blank? # or .empty?\n```","summary":"

Returns #offset value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":373,"url":null},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset"}},{"id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"optimize\ntable(table)\n"}},{"id":"optimize:QueryBuilder-instance-method","html_id":"optimize:QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :optimize\nself\n"}},{"id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":310,"url":null},"def":{"name":"or_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"\", \"OR\")"}},{"id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":286,"url":null},"def":{"name":"or_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"\", \"OR\")\nself\n"}},{"id":"or_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":331,"url":null},"def":{"name":"or_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"\", \"OR\")"}},{"id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":318,"url":null},"def":{"name":"or_not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"OR\")"}},{"id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":296,"url":null},"def":{"name":"or_not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"OR\")\nself\n"}},{"id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":339,"url":null},"def":{"name":"or_not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"OR\")"}},{"id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":271,"url":null},"def":{"name":"or_not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"OR\")"}},{"id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":263,"url":null},"def":{"name":"or_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"\", \"OR\")"}},{"id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","html_id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","name":"order_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"args_string":"(field : FieldType, dir = nil) : QueryBuilder","args_html":"(field : FieldType, dir = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":384,"url":null},"def":{"name":"order_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"field = field.to_s\norder_by = if dir.nil?\n ( (field.includes?(\" \")) || (field == \"rand()\")) ? field : \"#{field} ASC\"\nelse\n \"#{field} #{dir.to_s.upcase}\"\nend\n@order_by = @order_by + (@order_by.empty? ? order_by : \", #{order_by}\")\nself\n"}},{"id":"paginate(per_page,page):QueryBuilder-instance-method","html_id":"paginate(per_page,page):QueryBuilder-instance-method","name":"paginate","doc":"Sets `offset` and `limit` to get pagination-compatible results.","summary":"

Sets #offset and #limit to get pagination-compatible results.

","abstract":false,"args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"args_string":"(per_page, page) : QueryBuilder","args_html":"(per_page, page) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":378,"url":null},"def":{"name":"paginate","args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@limit = add_arg(per_page)\n@offset = add_arg(((page > 0 ? page : 1) - 1) * per_page)\nself\n"}},{"id":"ph(position:Int):String-instance-method","html_id":"ph(position:Int):String-instance-method","name":"ph","doc":"Adds placeholder for a SQL argument.","summary":"

Adds placeholder for a SQL argument.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int) : String","args_html":"(position : Int) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":44,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@placeholder"}},{"id":"query(&):QueryBuilder-instance-method","html_id":"query(&):QueryBuilder-instance-method","name":"query","doc":"Generates a raw query.\n> Be careful, you have to manage arguments and quotes.\n\nExample:\n\n```\nputs builder.query { \"\n SELECT * FROM tests\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n LIMIT 1\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\nLIMIT 1\n```","summary":"

Generates a raw query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":284,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :query\n@query = \" #{with QueryBuilderScope.new(self) yield} \"\nself\n"}},{"id":"query_count:Int-instance-method","html_id":"query_count:Int-instance-method","name":"query_count","doc":"Returns number of queries made by the current instance.","summary":"

Returns number of queries made by the current instance.

","abstract":false,"args":[],"args_string":" : Int","args_html":" : Int","location":{"filename":"src/query_builder/builder.cr","line_number":310,"url":null},"def":{"name":"query_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int","visibility":"Public","body":"@query_count"}},{"id":"query_method:Symbol?-instance-method","html_id":"query_method:Symbol?-instance-method","name":"query_method","doc":"Returns the query method.","summary":"

Returns the query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":305,"url":null},"def":{"name":"query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@query_method"}},{"id":"quote(field:FieldType):String-instance-method","html_id":"quote(field:FieldType):String-instance-method","name":"quote","doc":"Wraps *field* with quotes (`QUOTE`).","summary":"

Wraps field with quotes (QUOTE).

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":39,"url":null},"def":{"name":"quote","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"\"#{QUOTE}#{field}#{QUOTE}\""}},{"id":"repair:QueryBuilder-instance-method","html_id":"repair:QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :repair\nself\n"}},{"id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"repair\ntable(table)\n"}},{"id":"reset_query-instance-method","html_id":"reset_query-instance-method","name":"reset_query","doc":"Resets current query.","summary":"

Resets current query.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"reset_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@query_method = nil\n@query = \"\"\n@data_kv = \"\"\n@data = nil\n@options = nil\n@returning = nil\n@args = [] of DBValue\n@select = \"*\"\n@table = \"\"\n@join = \"\"\n@where = \"\"\n@group_by = \"\"\n@having = \"\"\n@order_by = \"\"\n@limit = \"\"\n@offset = \"\"\nnil\n"}},{"id":"returning(*name:FieldType):QueryBuilder-instance-method","html_id":"returning(*name:FieldType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":450,"url":null},"def":{"name":"returning","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.returning(name)"}},{"id":"returning:String?-instance-method","html_id":"returning:String?-instance-method","name":"returning","doc":"Returns the SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

Returns the SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[],"args_string":" : String?","args_html":" : String?","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":456,"url":null},"def":{"name":"returning","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String | ::Nil","visibility":"Public","body":"@returning"}},{"id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":432,"url":null},"def":{"name":"returning","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if query_method == (:insert)\nelse\n raise(DBX::Error.new(\"\\\"returning\\\" method SHOULD be used only with \\\"insert\\\" statement.\"))\nend\n_fields = _build_selected_fields(fields)\n@returning = if @returning.nil? || ((@returning.not_nil!.compare(\"*\")) == 0)\n _fields\nelse\n \"#{@returning}, #{_fields}\"\nend\nself\n"}},{"id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_join","doc":"Adds `RIGHT JOIN` to the current query.","summary":"

Adds RIGHT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT\")"}},{"id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_outer_join","doc":"Adds `RIGHT OUTER JOIN` to the current query.","summary":"

Adds RIGHT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT OUTER\")"}},{"id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":136,"url":null},"def":{"name":"select","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"_fields = _build_selected_fields(fields)\n@select = (@select.compare(\"*\")) == 0 ? _fields : \"#{@select}, #{_fields}\"\nself\n"}},{"id":"select:String-instance-method","html_id":"select:String-instance-method","name":"select","doc":"Returns selected field(s). Default is `*`.\n\n```\nputs builder.select\n```","summary":"

Returns selected field(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":152,"url":null},"def":{"name":"select","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@select"}},{"id":"select(*name:FieldType):QueryBuilder-instance-method","html_id":"select(*name:FieldType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":143,"url":null},"def":{"name":"select","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.select(name)"}},{"id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","name":"sum","doc":"Adds `SUM` to the current query.","summary":"

Adds SUM to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"sum","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"sum = \"SUM(#{field})\"\nif name.nil?\nelse\n sum = sum + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? sum : \"#{@select}, #{sum}\"\nself\n"}},{"id":"table(&):QueryBuilder-instance-method","html_id":"table(&):QueryBuilder-instance-method","name":"table","doc":"Defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":97,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"table(*name:FieldType):QueryBuilder-instance-method","html_id":"table(*name:FieldType):QueryBuilder-instance-method","name":"table","doc":"Targets tables defined by variadic arguments.\n\n```\nbuilder.table(:table1, :table2)\n```","summary":"

Targets tables defined by variadic arguments.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":79,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"table(name)"}},{"id":"table:String-instance-method","html_id":"table:String-instance-method","name":"table","doc":"Returns table name(s). Returns empty string if no table has been defined.\n\n```\nputs builder.table unless builder.table.blank? # or .empty?\n```","summary":"

Returns table name(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":107,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@table"}},{"id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"table","doc":"Targets one or more tables.","summary":"

Targets one or more tables.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"args_string":"(name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":68,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = name.is_a?(FieldsType) ? name.join(\", \") : name.to_s\nself\n"}},{"id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","html_id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","name":"to_data_h","doc":"Converts `NamedTuple` to `DataHashType`.","summary":"

Converts NamedTuple to DataHashType.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : DataHashType","args_html":"(data : Hash | NamedTuple) : DataHashType","location":{"filename":"src/query_builder/builder.cr","line_number":23,"url":null},"def":{"name":"to_data_h","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DataHashType","visibility":"Public","body":"h = DataHashType.new\ndata.each do |k, v|\n h[k] = v\nend\nh\n"}},{"id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":137,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :update\nif data\nelse\n raise(Error.new(\"No data to update\"))\nend\n@data_kv = add_args_and_kv_from_data(to_data_h(data))\nself\n"}},{"id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":144,"url":null},"def":{"name":"update","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\ntable(table)\n"}},{"id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","args_html":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":149,"url":null},"def":{"name":"update","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\n@query_method = :update_one\nself.where(pk_name, pk_value)\n"}},{"id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","name":"where","doc":"Where clause.","summary":"

Where clause.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":224,"url":null},"def":{"name":"where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where = if @operators.includes?(op_or_val.to_s)\n \" #{type}#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \" #{type}#{field} = #{add_arg(op_or_val)}\"\nend\n@where = @where + (@where.empty? ? where : \" #{and_or}#{where}\")\nself\n"}},{"id":"where(&):QueryBuilder-instance-method","html_id":"where(&):QueryBuilder-instance-method","name":"where","doc":"Adds a raw `where` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").where { \"\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\n```","summary":"

Adds a raw #where to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":258,"url":null},"def":{"name":"where","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilder/ArgsType","path":"DBX/QueryBuilder/ArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::ArgsType","name":"ArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Argument(s) for SQL query.","summary":"

Argument(s) for SQL query.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DataHashType","path":"DBX/QueryBuilder/DataHashType.html","kind":"alias","full_name":"DBX::QueryBuilder::DataHashType","name":"DataHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type of the data `Hash`,\nused as a KV container for insert and update.","summary":"

The type of the data Hash, used as a KV container for insert and update.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DBValue","path":"DBX/QueryBuilder/DBValue.html","kind":"alias","full_name":"DBX::QueryBuilder::DBValue","name":"DBValue","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"DB Value.","summary":"

DB Value.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldsType","path":"DBX/QueryBuilder/FieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldsType","name":"FieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol))","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for several fields contained in an `Enumerable` (e.g: `Array` or `Tuple`).","summary":"

The type for several fields contained in an Enumerable (e.g: Array or Tuple).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldType","path":"DBX/QueryBuilder/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Field type.","summary":"

Field type.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/OneOrMoreFieldsType","path":"DBX/QueryBuilder/OneOrMoreFieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::OneOrMoreFieldsType","name":"OneOrMoreFieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":18,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol)","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for one or more fields.","summary":"

The type for one or more fields.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/SQLandArgsType","path":"DBX/QueryBuilder/SQLandArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::SQLandArgsType","name":"SQLandArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Tuple(String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil))","aliased_html":"{String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The return type of `build` method.","summary":"

The return type of build method.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/QueryBuilderScope","path":"DBX/QueryBuilderScope.html","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope","abstract":false,"superclass":{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"dbx/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/scope.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Handy `QueryBuilder` scope used into `Block`.","summary":"

Handy QueryBuilder scope used into Block.

","class_methods":[],"constructors":[{"id":"new(builder:QueryBuilder)-class-method","html_id":"new(builder:QueryBuilder)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"args_string":"(builder : QueryBuilder)","args_html":"(builder : QueryBuilder)","location":{"filename":"src/query_builder/scope.cr","line_number":13,"url":null},"def":{"name":"new","args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(builder)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"arg(value):String-instance-method","html_id":"arg(value):String-instance-method","name":"arg","doc":"Same as `QueryBuilder#add_arg`","summary":"

Same as QueryBuilder#add_arg

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/scope.cr","line_number":17,"url":null},"def":{"name":"arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.add_arg(value)"}},{"id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","html_id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"args_string":"(field : FieldType, io : IO::Memory) : IO::Memory","args_html":"(field : FieldType, io : IO::Memory) : IO::Memory","location":{"filename":"src/query_builder/scope.cr","line_number":22,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"IO::Memory","visibility":"Public","body":"@builder.quote(field, io)"}},{"id":"q(field:FieldType):String-instance-method","html_id":"q(field:FieldType):String-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/scope.cr","line_number":27,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.quote(field)"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilderScope/FieldType","path":"DBX/QueryBuilderScope/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilderScope::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/scope.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilderScope","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}]}} \ No newline at end of file diff --git a/docs/search-index.js b/docs/search-index.js index 471065e..c390c7e 100644 --- a/docs/search-index.js +++ b/docs/search-index.js @@ -1 +1 @@ -crystal_doc_search_index_callback({"repository_name":"dbx","body":"# :sparkles: DBX\n\n[![CI Status](https://github.com/Nicolab/crystal-dbx/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-dbx/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-dbx.svg)](https://github.com/Nicolab/crystal-dbx/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-dbx/)\n\n* DB connections manager\n* Query builder\n* ORM (alpha)\n\nDBX is a [Crystal lang](https://crystal-lang.org) module to query the database, built on top of [crystal-db](https://github.com/crystal-lang/crystal-db) (common API for DB drivers).\n\nDBX is designed in a decoupled way to embed only the necessary features (multi-connections manager, query builder, query executor and ORM).\n\n## Documentation\n\n* šŸš€ [Guide](/guide/README.md)\n* šŸ“˜ [API doc](https://nicolab.github.io/crystal-dbx/)\n* :bookmark_tabs: [Spec tests](https://github.com/Nicolab/crystal-dbx/tree/master/spec)\n\n## Contributing\n\n1. Fork it ().\n2. Create your feature branch (`git checkout -b my-new-feature`).\n3. See [Development](#Development).\n4. Commit your changes (`git commit -am 'Add some feature'`).\n5. Push to the branch (`git push origin my-new-feature`).\n6. Create a new Pull Request.\n\n### Development\n\n1. You only need Git, Docker and Docker-compose installed on your machine.\n2. Clone this repo and run `./scripts/prepare`.\n3. Run first `docker-compose up`,\n 1. then enter to container `docker-compose exec test_pg bash` (or `test_sqlite` service),\n 2. into the container `just dev-spec`.\n4. Check the project before committing or pushing, from the host: `./scripts/check`\n\nIt's just Docker and docker-compose, you can directly type all the commands Docker and docker-compose.\n\nāœØ Example:\n\n_Terminal 1_\n\n```sh\n# Start the dev stack\ndocker-compose up\n```\n\n_Terminal 2_\n\n```sh\n# enter in the test_pg container\ndocker-compose exec test_pg bash\n\n# then in the test_pg container\ncrystal run ./src/app.cr\n\n# or with a recipe (helper)\njust dev-spec # <= auto reload when the code change\n\n# recipe list\njust --list\n```\n\nAlso, quickly:\n\n* `docker-compose run --rm test_pg crystal spec`\n* or `docker-compose run --rm test_pg just dev-spec`\n* when you are done: `docker-compose down --remove-orphans`\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-dbx/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n* [Nicolas Talle (@Nicolab)](https://github.com/Nicolab) - Creator and maintainer.\n* Thanks to [@ilourt](https://github.com/ilourt) for the feedbacks and thoughts.\n* This project is useful to you? [Sponsor the developer](https://github.com/sponsors/Nicolab).\n","program":{"html_id":"dbx/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"dbx","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX","path":"DBX.html","kind":"module","full_name":"DBX","name":"DBX","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":60,"url":null},{"filename":"src/query_builder/builder.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":8,"url":null},{"filename":"src/query_builder/executor.cr","line_number":8,"url":null},{"filename":"src/query_builder/scope.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-dbx/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"DBX is a helper to handle multi DBs using the compatible drivers\nwith the common `crystal-db` module.\n\nExample with PostgreSQL:\n\n```\n# Connection URI / DSL https://www.postgresql.org/docs/current/libpq-connect.html#h5o-9\ndb = DBX.open(\"app\", \"postgres://...\", true)\n\npp DBX.db?(\"app\") ? \"defined\" : \"not defined\"\n\ndb.query \"select id, created_at, email from users\" do |rs|\n rs.each do\n id = rs.read(Int32)\n created_at = rs.read(Time)\n email = rs.read(String)\n puts \"##{id}: #{email} #{created_at}\"\n end\nend\n\n# Closes all connections of this DB connection pool and remove this DB connection pool.\nDBX.destroy(\"app\")\n```\n\nModel:\n\n```\nclass User\n include DBX::ORM::DSL\n\n field lang : String\n\n @[JSON::Field(key: \"firstName\")]\n field first_name : String?\nend\n\ndb = DBX.open \"app\", App.cfg.db_uri\n\nuser = User.from_rs(db.query(\"SELECT id, lang, first_name FROM users\"))\npp user.to_json\n\nuser = User.from_json \"{\\\"lang\\\":\\\"fr\\\",\\\"firstName\\\":\\\"Nico\\\"}\"\npp user\n```\n\nSee also `DBX::ORM` for a more advanced model system and query builder.\n\nResources:\n- https://crystal-lang.github.io/crystal-db/api/index.html\n- https://github.com/Nicolab/crystal-dbx/tree/master/guide","summary":"

DBX is a helper to handle multi DBs using the compatible drivers with the common crystal-db module.

","class_methods":[{"id":"db(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"db(name:String,uri:String,strict=false):DB::Database-class-method","name":"db","doc":"Same as `.open`.","summary":"

Same as .open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":92,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"self.open(name, uri, strict)"}},{"id":"db(name:String):DB::Database-class-method","html_id":"db(name:String):DB::Database-class-method","name":"db","doc":"Uses a given DB connection pool.","summary":"

Uses a given DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Database","args_html":"(name : String) : DB::Database","location":{"filename":"src/dbx.cr","line_number":87,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"@@dbs[name]"}},{"id":"db?(name:String):Bool-class-method","html_id":"db?(name:String):Bool-class-method","name":"db?","doc":"Checks that a DB connection pool exists.","summary":"

Checks that a DB connection pool exists.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Bool","args_html":"(name : String) : Bool","location":{"filename":"src/dbx.cr","line_number":82,"url":null},"def":{"name":"db?","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@@dbs.has_key?(name)"}},{"id":"dbs:DBHashType-class-method","html_id":"dbs:DBHashType-class-method","name":"dbs","doc":"Returns all `DB::Database` instances.","summary":"

Returns all DB::Database instances.

","abstract":false,"args":[],"args_string":" : DBHashType","args_html":" : DBHashType","location":{"filename":"src/dbx.cr","line_number":77,"url":null},"def":{"name":"dbs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBHashType","visibility":"Public","body":"@@dbs"}},{"id":"destroy(name:String)-class-method","html_id":"destroy(name:String)-class-method","name":"destroy","doc":"Closes all connections of the DB connection pool *name*\nand remove the *name* DB connection pool.","summary":"

Closes all connections of the DB connection pool name and remove the name DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String)","args_html":"(name : String)","location":{"filename":"src/dbx.cr","line_number":112,"url":null},"def":{"name":"destroy","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@dbs.has_key?(name)\n begin\n (self.db(name)).close\n rescue e : Exception\n puts(\"\\nšŸ‘» DBX.destroy: error caught when closing:\")\n pp(e)\n end\n @@dbs.delete(name)\nend"}},{"id":"destroy:Tuple(Int32,Int32)-class-method","html_id":"destroy:Tuple(Int32,Int32)-class-method","name":"destroy","doc":"Destroy all DB connection pool and and their connections.","summary":"

Destroy all DB connection pool and and their connections.

","abstract":false,"args":[],"args_string":" : Tuple(Int32, Int32)","args_html":" : Tuple(Int32, Int32)","location":{"filename":"src/dbx.cr","line_number":125,"url":null},"def":{"name":"destroy","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple(Int32, Int32)","visibility":"Public","body":"size = @@dbs.size\n@@dbs.each_key do |name|\n self.destroy(name)\nend\n{@@dbs.size, size}\n"}},{"id":"open(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"open(name:String,uri:String,strict=false):DB::Database-class-method","name":"open","doc":"Ensures only once DB connection pool by *name* is open.\nIf the DB connection pool *name* is already initialized, it is returned.\nRaises an error if *strict* is *true* and the DB connection pool *name* is\nalready opened.","summary":"

Ensures only once DB connection pool by name is open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":100,"url":null},"def":{"name":"open","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"if @@dbs.has_key?(name)\n if strict\n else\n return @@dbs[name]\n end\n raise(\"'#{name}' DB connection pool is already opened\")\nend\n@@dbs[name] = DB.open(uri)\n"}},{"id":"pool_open_connections(name:String):Int32-class-method","html_id":"pool_open_connections(name:String):Int32-class-method","name":"pool_open_connections","doc":"Gets the number of the connections opened in the pool of *name*.","summary":"

Gets the number of the connections opened in the pool of name.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Int32","args_html":"(name : String) : Int32","location":{"filename":"src/dbx.cr","line_number":142,"url":null},"def":{"name":"pool_open_connections","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"pool_stats = self.pool_stats(name)\nif pool_stats\nelse\n return 0\nend\npool_stats.open_connections\n"}},{"id":"pool_stats(name:String):DB::Pool::Stats?-class-method","html_id":"pool_stats(name:String):DB::Pool::Stats?-class-method","name":"pool_stats","doc":"Pool stats\nhttps://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html","summary":"

Pool stats https://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Pool::Stats?","args_html":"(name : String) : DB::Pool::Stats?","location":{"filename":"src/dbx.cr","line_number":137,"url":null},"def":{"name":"pool_stats","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Pool::Stats | ::Nil","visibility":"Public","body":"if self.db?(name)\n (self.db(name)).pool.stats\nend"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"around_query_or_exec(&block)-macro","html_id":"around_query_or_exec(&block)-macro","name":"around_query_or_exec","doc":"This macro allows injecting code to be run before and after the execution\nof the request. It should return the yielded value. It must be called with 1\nblock argument that will be used to pass the `args : Enumerable`.\nThis macro should be called at the top level, not from a method.\n\n> Be careful of the performance penalty that each hook may cause,\n be aware that your code will be executed at each query and exec.\n\n```\nDBX.around_query_or_exec do |args|\n puts \"before\"\n res = yield\n puts \"after\"\n\n puts res.class\n puts \"exec\" if res.is_a?(DB::ExecResult)\n puts \"query\" if res.is_a?(DB::ResultSet)\n\n puts \"with args:\"\n pp args\n\n res\nend\n```\n\nExample to measure query execution time:\n\n```\nDBX.around_query_or_exec do |args|\n start = Time.monotonic\n res = yield\n elapsed_time = Time.monotonic - start\n\n puts \"Query execution time: #{elapsed_time}\"\n res\nend\n```","summary":"

This macro allows injecting code to be run before and after the execution of the request.

","abstract":false,"args":[],"args_string":"(&block)","location":{"filename":"src/dbx.cr","line_number":185,"url":null},"def":{"name":"around_query_or_exec","args":[],"double_splat":null,"splat_index":null,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"visibility":"Public","body":" class ::DB::Statement\n def_around_query_or_exec do |args|\n \n{{ block.body }}\n\n \nend\n \nend\n \n"}}],"types":[{"html_id":"dbx/DBX/Adapter","path":"DBX/Adapter.html","kind":"module","full_name":"DBX::Adapter","name":"Adapter","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/adapter.cr","line_number":11,"url":null},{"filename":"src/adapter/pg.cr","line_number":12,"url":null},{"filename":"src/adapter/sqlite.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DB adapter(s) used by `DBX::QueryBuilder` and `DBX::ORM`.","summary":"

DB adapter(s) used by DBX::QueryBuilder and DBX::ORM.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"inject_pg-macro","html_id":"inject_pg-macro","name":"inject_pg","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/pg.cr","line_number":14,"url":null},"def":{"name":"inject_pg","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::PostgreSQL\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}},{"id":"inject_sqlite-macro","html_id":"inject_sqlite-macro","name":"inject_sqlite","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/sqlite.cr","line_number":14,"url":null},"def":{"name":"inject_sqlite","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::SQLite\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}}],"types":[{"html_id":"dbx/DBX/Adapter/Base","path":"DBX/Adapter/Base.html","kind":"class","full_name":"DBX::Adapter::Base","name":"Base","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/adapter.cr","line_number":13,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"}],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"Base adapter.","summary":"

Base adapter.

","class_methods":[{"id":"builder_class:QueryBuilder.class-class-method","html_id":"builder_class:QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class.","summary":"

Returns query builder class.

","abstract":false,"args":[],"args_string":" : QueryBuilder.class","args_html":" : QueryBuilder.class","location":{"filename":"src/adapter/adapter.cr","line_number":34,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder.class","visibility":"Public","body":"raise(NotImplementedError.new(\"'#{self}' model MUST define '#{self}.builder_class' method.\"))"}},{"id":"new_builder:QueryBuilder-class-method","html_id":"new_builder:QueryBuilder-class-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":29,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"constructors":[{"id":"new(db:DB::Database)-class-method","html_id":"new(db:DB::Database)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"args_string":"(db : DB::Database)","args_html":"(db : DB::Database)","location":{"filename":"src/adapter/adapter.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(db)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":true,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/adapter.cr","line_number":42,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"db:DB::Database-instance-method","html_id":"db:DB::Database-instance-method","name":"db","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/adapter/adapter.cr","line_number":19,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@db"}},{"id":"new_builder:QueryBuilder-instance-method","html_id":"new_builder:QueryBuilder-instance-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":24,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","path":"DBX/Adapter/PGQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":58,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for PostgreSQL.\n:inherit:","summary":"

QueryBuilder for PostgreSQL.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"ph(position:Int)-instance-method","html_id":"ph(position:Int)-instance-method","name":"ph","doc":"Adds placeholder specific to PostgreSQL.\nAdds placeholder for a SQL argument.","summary":"

Adds placeholder specific to PostgreSQL.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int)","args_html":"(position : Int)","location":{"filename":"src/adapter/pg.cr","line_number":65,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"#{@placeholder}#{position}\""}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PostgreSQL","path":"DBX/Adapter/PostgreSQL.html","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"PostgreSQL adapter","summary":"

PostgreSQL adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.\n> To get recorded data, PostgreSQL adapter use `RETURNING` SQL statement.\n *pk_name* and *pk_type* are useless and ignored,\n thanks PostgreSQL `RETURNING` that makes it simpler and more efficient :)","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/pg.cr","line_number":37,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create\\\" only, without other statement except the table. \\\"Test.create\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\n((query.insert(data)).returning(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/PostgreSQL/QueryBuilder","path":"DBX/Adapter/PostgreSQL/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::PostgreSQL::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/pg.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::PGQueryBuilder","aliased_html":"DBX::Adapter::PGQueryBuilder","const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLite","path":"DBX/Adapter/SQLite.html","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"SQLite adapter","summary":"

SQLite adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/sqlite.cr","line_number":34,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create!\\\" only, without other statement except the table. \\\"Test.create!\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\ntable_name = query.builder.table.gsub(\"\\\"\", \"\")\nlast_id = (query.insert(data)).exec!.last_insert_id\nif last_id.nil?\n raise(DB::NoResultsError.new(\"Cannot create\"))\nend\n(((query.table(table_name)).find(pk_name, last_id)).select(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/SQLite/QueryBuilder","path":"DBX/Adapter/SQLite/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::SQLite::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::SQLiteQueryBuilder","aliased_html":"DBX::Adapter::SQLiteQueryBuilder","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","path":"DBX/Adapter/SQLiteQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":69,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for SQLite.\n:inherit:","summary":"

QueryBuilder for SQLite.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/DBHashType","path":"DBX/DBHashType.html","kind":"alias","full_name":"DBX::DBHashType","name":"DBHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":62,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, DB::Database)","aliased_html":"Hash(String, DB::Database)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/Error","path":"DBX/Error.html","kind":"class","full_name":"DBX::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":65,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/Model/Error","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when an error occurred, related with `DB` or `DBX`.","summary":"

Raised when an error occurred, related with DB or DBX.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/NotSupportedError","path":"DBX/NotSupportedError.html","kind":"class","full_name":"DBX::NotSupportedError","name":"NotSupportedError","abstract":false,"superclass":{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},"ancestors":[{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":71,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when a method is not supported.\n\nThis can be used either to stub out method bodies,\nor when the method is not supported on the current adapter.","summary":"

Raised when a method is not supported.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM","path":"DBX/ORM.html","kind":"module","full_name":"DBX::ORM","name":"ORM","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model.cr","line_number":8,"url":null},{"filename":"src/orm/model_mixin.cr","line_number":8,"url":null},{"filename":"src/orm/model_query.cr","line_number":8,"url":null},{"filename":"src/orm/orm.cr","line_number":18,"url":null},{"filename":"src/orm/schema/schema.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DBX ORM (Object-Relational Mapping).","summary":"

DBX ORM (Object-Relational Mapping).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model","path":"DBX/ORM/Model.html","kind":"class","full_name":"DBX::ORM::Model","name":"Model","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":48,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Base class for all models.\n\nExample, creation of a model for a table `users`:\n\n```\nclass User < DBX::ORM::Model\n adapter :pg\n\n class Schema # < DBX::ORM::Schema#(User)\n field id : Int64?\n field name : String\n field about : String\n field age : Int32\n end\nend\n```\n\nCustomize `ModelQuery` used by `User` model:\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # Custom select\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Base class for all models.

","class_methods":[{"id":"connection:String-class-method","html_id":"connection:String-class-method","name":"connection","doc":"DB connection name used by this `Model` instance.","summary":"

DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/model.cr","line_number":176,"url":null},"def":{"name":"connection","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@conn_name"}},{"id":"db:DB::Database-class-method","html_id":"db:DB::Database-class-method","name":"db","doc":"Returns DB connection name used by this `Model` instance.","summary":"

Returns DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/orm/model.cr","line_number":181,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"DBX.db(connection)"}},{"id":"models-class-method","html_id":"models-class-method","name":"models","doc":"Returns array of all non-abstract subclasses of *DBX::ORM::Model.\n\n```\nDBX::ORM::Model.models # => [Contact, Address, User]\n```","summary":"

Returns array of all non-abstract subclasses of *DBX::ORM::Model.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model.cr","line_number":190,"url":null},"def":{"name":"models","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% models = @type.all_subclasses.select do |m|\n !m.abstract?\nend %}\n {% if !models.empty? %}\n [\n {% for model in models %}\n ::{{ model.name }},\n {% end %}\n ]\n {% else %}\n [] of ::DBX::ORM::Model.class\n {% end %}\n {% end %}"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model/Error","path":"DBX/ORM/Model/Error.html","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":53,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Model","kind":"class","full_name":"DBX::ORM::Model","name":"Model"},"doc":"Model error.","summary":"

Model error.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/ModelMixin","path":"DBX/ORM/ModelMixin.html","kind":"module","full_name":"DBX::ORM::ModelMixin(Model, ModelQuery)","name":"ModelMixin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model_mixin.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Mixin for `Model` class.\n> Automatically injected into the models.","summary":"

Mixin for Model class.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","html_id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","name":"create!","doc":"Creates a new resource and returns.","summary":"

Creates a new resource and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","args_html":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","location":{"filename":"src/orm/model_mixin.cr","line_number":33,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Model::Schema","visibility":"Public","body":"query.create!(data, returning: returning)"}},{"id":"delete(pk_value):ModelQuery-instance-method","html_id":"delete(pk_value):ModelQuery-instance-method","name":"delete","doc":"Deletes one resource by its primary key.","summary":"

Deletes one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":56,"url":null},"def":{"name":"delete","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete(Model.pk_name, pk_value)"}},{"id":"delete:ModelQuery-instance-method","html_id":"delete:ModelQuery-instance-method","name":"delete","doc":"Deletes one or more resources.","summary":"

Deletes one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":51,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete"}},{"id":"find(pk_value):ModelQuery-instance-method","html_id":"find(pk_value):ModelQuery-instance-method","name":"find","doc":"Find one resource by its primary key.","summary":"

Find one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":23,"url":null},"def":{"name":"find","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find(\"#{self.table_name}.#{Model.pk_name}\", pk_value)"}},{"id":"find:ModelQuery-instance-method","html_id":"find:ModelQuery-instance-method","name":"find","doc":"Find one or more resources.","summary":"

Find one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":18,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find"}},{"id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","name":"insert","doc":"Inserts a new resource.","summary":"

Inserts a new resource.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":28,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.insert(data)"}},{"id":"query:ModelQuery-instance-method","html_id":"query:ModelQuery-instance-method","name":"query","doc":"Creates a new `ModelQuery` instance.","summary":"

Creates a new ModelQuery instance.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":13,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"(ModelQuery.new(self.adapter)).table(self.table_name)"}},{"id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Updates one resource by its primary key.","summary":"

Updates one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_value, data : Hash | NamedTuple) : ModelQuery","args_html":"(pk_value, data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":46,"url":null},"def":{"name":"update","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(Model.pk_name, pk_value, data)"}},{"id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Update one or more resources.","summary":"

Update one or more resources.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":41,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(data)"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/ModelQuery","path":"DBX/ORM/ModelQuery.html","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery","abstract":false,"superclass":{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},"ancestors":[{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model_query.cr","line_number":35,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Generic `ModelQuery` class.\n> Automatically injected into the models.\n\nIf you want to customize the queries of a model, you can define\nyou own `ModelQuery` into this model.\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # A custom `select`\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Generic ModelQuery class.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = ModelQuery(Model).allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","html_id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\ntest = Test.create!(data)\nputs test.id\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","args_html":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","location":{"filename":"src/orm/model_query.cr","line_number":129,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"create!(data, as: Model::Schema, returning: returning, pk_name: Model.pk_name, pk_type: Model.pk_type)"}},{"id":"query_all-instance-method","html_id":"query_all-instance-method","name":"query_all","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":152,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"query_one-instance-method","html_id":"query_one-instance-method","name":"query_one","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":140,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"query_one!-instance-method","html_id":"query_one!-instance-method","name":"query_one!","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":146,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}},{"id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"rel","doc":"Refers to the result of a join in a defined `relation` property path.\n\n```\nusers = User\n .find\n .rel(\"groups\")\n .left_join(\"groups\", \"groups.id\", \"users.group_id\")\n .to_a\n```","summary":"

Refers to the result of a join in a defined relation property path.

","abstract":false,"args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":91,"url":null},"def":{"name":"rel","args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"r = Model::Schema.find_relation_from_path(path.to_s)\n@relations << r[:relation]\nselect_all.select_all(r[:model], table_alias)\n"}},{"id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects the relation fields.\nThis method is automatically called by the methods related to the joins with a model class.","summary":"

Selects the relation fields.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":63,"url":null},"def":{"name":"select_all","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if selected_all?(model_class, table_alias)\n return self\nend\nif table_alias\n table_alias = table_alias.to_s\n sql_fields = model_class.schema_class.fields.join(\",\") do |_, field|\n \"#{table_alias}.#{field[:name]}\"\n end\nelse\n sql_fields = model_class.schema_class.sql_fields\nend\nself.select(sql_fields)\n@rel_fields_selected[\"#{model_class}=>#{table_alias}\"] = true\nself\n"}},{"id":"select_all:ModelQuery(Model)-instance-method","html_id":"select_all:ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects all SQL fields.","summary":"

Selects all SQL fields.

","abstract":false,"args":[],"args_string":" : ModelQuery(Model)","args_html":" : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":47,"url":null},"def":{"name":"select_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if @fields_selected\n return self\nend\nself.select(Model::Schema.sql_fields)\n@fields_selected = true\nself\n"}},{"id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","html_id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the relation fields are selected, `false` otherwise.\nSee `select_rel_fields`","summary":"

Returns true if the relation fields are selected, false otherwise.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","location":{"filename":"src/orm/model_query.cr","line_number":57,"url":null},"def":{"name":"selected_all?","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@rel_fields_selected.has_key?(\"#{model_class}=>#{table_alias}\")"}},{"id":"selected_all?:Bool-instance-method","html_id":"selected_all?:Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the model fields are selected, `false` otherwise.\nSee `select_all`","summary":"

Returns true if the model fields are selected, false otherwise.

","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/orm/model_query.cr","line_number":42,"url":null},"def":{"name":"selected_all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@fields_selected"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":188,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Shortcut, same as `query_all`.","summary":"

Shortcut, same as #query_all.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":182,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":177,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o-instance-method","html_id":"to_o-instance-method","name":"to_o","doc":"Shortcut, same as `query_one`.","summary":"

Shortcut, same as #query_one.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":166,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":172,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!-instance-method","html_id":"to_o!-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!`.","summary":"

Shortcut, same as #query_one!.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":160,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema","path":"DBX/ORM/Schema.html","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":14,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"FIELDS","name":"FIELDS","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null},{"id":"RELATIONS","name":"RELATIONS","value":"{} of String => ASTNode","doc":null,"summary":null}],"included_modules":[{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"`Model` Schema.","summary":"

Model Schema.

","class_methods":[{"id":"fields:MetaFieldHash-class-method","html_id":"fields:MetaFieldHash-class-method","name":"fields","doc":"Returns all SQL fields definitions.","summary":"

Returns all SQL fields definitions.

","abstract":false,"args":[],"args_string":" : MetaFieldHash","args_html":" : MetaFieldHash","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"MetaFieldHash","visibility":"Public","body":"@@fields"}},{"id":"from_rs(rs:DB::ResultSet)-class-method","html_id":"from_rs(rs:DB::ResultSet)-class-method","name":"from_rs","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"from_rs","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n objs = Array(self).new\n rs.each do\n objs << (self.new(rs))\n end\n objs\nensure\n rs.close\nend"}},{"id":"sql_fields:String-class-method","html_id":"sql_fields:String-class-method","name":"sql_fields","doc":"Returns the SQL fields of the model separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_fields"}},{"id":"sql_rel_fields:String-class-method","html_id":"sql_rel_fields:String-class-method","name":"sql_rel_fields","doc":"Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_rel_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_rel_fields"}}],"constructors":[{"id":"new(rs:DB::ResultSet)-class-method","html_id":"new(rs:DB::ResultSet)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"new","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"instance = allocate\ninstance.initialize(__set_for_db_serializable: rs)\nif instance.responds_to?(:finalize)\n GC.add_finalizer(instance)\nend\ninstance\n"}},{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"args_string":"(pull : JSON::PullParser)","args_html":"(pull : JSON::PullParser)","location":{"filename":"src/orm/schema/schema.cr","line_number":23,"url":null},"def":{"name":"new","args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_from_json_pull_parser(pull)"}}],"instance_methods":[{"id":"_pk-instance-method","html_id":"_pk-instance-method","name":"_pk","doc":"Same as `_pk` but may return `nil` when the record hasn't been saved\ninstead of raising.","summary":"

Same as #_pk but may return nil when the record hasn't been saved instead of raising.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":40,"url":null},"def":{"name":"_pk","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.id"}},{"id":"_pk!-instance-method","html_id":"_pk!-instance-method","name":"_pk!","doc":"Always returns this record's primary key value, even when the primary key\nisn't named `_pk`.","summary":"

Always returns this record's primary key value, even when the primary key isn't named #_pk.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":32,"url":null},"def":{"name":"_pk!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk.not_nil!"}},{"id":"_ukey-instance-method","html_id":"_ukey-instance-method","name":"_ukey","doc":"Unique (virtual) key used to compare the uniqueness of models.\nBy default this method returns the primary key (`_pk`) value.\n\nThis method avoid to rely directly on the primary key in case there is none in\nthe structure of the SQL table (even if there should always be one).\nUsed in the relation algorithm.\nAlso, can be useful when there is a need to check the uniqueness in other cases.\n\nIf for some reason your model does not have a primary key,\nyou can override this method to return a unique result\nrelated to the fields in your table, for example:\n\n```\n@[DB::Field(ignore: true)]\n@[JSON::Field(ignore: true)]\ndef _ukey\n \"#{self.group_id}.#{self.user_id}\"\nend\n```","summary":"

Unique (virtual) key used to compare the uniqueness of models.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":65,"url":null},"def":{"name":"_ukey","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk"}}],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Schema/MetaField","path":"DBX/ORM/Schema/MetaField.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaField","name":"MetaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":16,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String)","aliased_html":"{name: String, rel_name: String, sql: String, rel_sql: String}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/MetaFieldHash","path":"DBX/ORM/Schema/MetaFieldHash.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaFieldHash","name":"MetaFieldHash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":17,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String))","aliased_html":"Hash(String, {name: String, rel_name: String, sql: String, rel_sql: String})","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/RelationDef","path":"DBX/ORM/Schema/RelationDef.html","kind":"alias","full_name":"DBX::ORM::Schema::RelationDef","name":"RelationDef","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool)","aliased_html":"{name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/SchemaField","path":"DBX/ORM/SchemaField.html","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/field.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"field(name)-macro","html_id":"field(name)-macro","name":"field","doc":"Defines a SQL field.","summary":"

Defines a SQL field.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"args_string":"(name)","location":{"filename":"src/orm/schema/def/field.cr","line_number":10,"url":null},"def":{"name":"field","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if name.is_a?(TypeDeclaration) %}\n {% full_name = \"#{model_class}.#{name.var}\"\nif FIELDS[full_name].nil?\n FIELDS[full_name] = HashLiteral(String, ASTNode).new\nend\nFIELDS[full_name] = {model: model_class, name: name.var, full_name: full_name.id, rel_name: \"__#{model_class}_#{name.var}\", type: name.type, type_class: \"#{name.type.is_a?(Union) ? \"(#{name.type})\".id : name.type}.class\".id, default: name.value || \"nil\".id}\n %}\n\n @{{ name.var }} : {{ name.type }}{% if name.value %} = {{ name.value }}{% end %}\n def {{ name.var }} : {{ name.type }}\n @{{ name.var }}\n end\n\n def {{ name.var }}=(value : {{ name.type }})\n @{{ name.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.field doesn't support \" + name.class_name) %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","path":"DBX/ORM/SchemaInjectFields.html","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/inject_fields.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_fields-macro","html_id":"orm_schema_inject_fields-macro","name":"orm_schema_inject_fields","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_fields.cr","line_number":9,"url":null},"def":{"name":"orm_schema_inject_fields","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" @@fields : MetaFieldHash = MetaFieldHash.new\n @@sql_fields : String = \"\"\n @@sql_rel_fields : String = \"\"\n\n \n# Returns all SQL fields definitions.\n\n def self.fields : MetaFieldHash\n @@fields\n \nend\n\n \n# Returns the SQL fields of the model separated by a comma (table.column, ...).\n\n def self.sql_fields : String\n @@sql_fields\n \nend\n\n \n# Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).\n\n def self.sql_rel_fields : String\n @@sql_rel_fields\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","path":"DBX/ORM/SchemaInjectForFinal.html","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal","abstract":false,"superclass":null,"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"locations":[{"filename":"src/orm/schema/inject_for_final.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_for_final-macro","html_id":"orm_schema_inject_for_final-macro","name":"orm_schema_inject_for_final","doc":"Finish for the final `Schema` class.","summary":"

Finish for the final Schema class.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_for_final.cr","line_number":13,"url":null},"def":{"name":"orm_schema_inject_for_final","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% model_relations = {} of Symbol => ASTNode %}\n\n\n \n{% for path, dec in RELATIONS %}\n {% if model_class == dec[:from_model] %}\n {% model_relations[path] = dec %}\n {% end %}\n {% end %}\n\n\n \n{% consts = @type.constants.map(&.symbolize) %}\n\n \n{% if consts.includes?(:DBValue) %}{% else %}\n alias DBValue = DBX::QueryBuilder::DBValue\n {% end %}\n\n\n \n# Returns model table name.\n\n def self.table_name : String\n model_class.table_name\n \nend\n\n \n# Returns model class.\n\n def self.model_class : \n{{ model_class }}\n.class\n \n{{ model_class }}\n\n \nend\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @@fields[{{ full_name }}] = {\n name: \"{{ dec[:name] }}\",\n rel_name: {{ dec[:rel_name] }},\n sql: \"#{table_name}.{{ dec[:name] }}\",\n rel_sql: \"#{table_name}.{{ dec[:name] }} AS {{ dec[:rel_name].id }}\"\n }\n {% end %}\n {% end %}\n\n\n @@sql_fields : String = self.fields.join(\",\") \n{ |_, f| f[:sql] }\n @@sql_rel_fields : String = self.fields.join(\",\") \n{ |_, f| f[:rel_sql] }\n\n \n# All DB fields of the `\n{{ model_class }}\n` model.\n\n alias FieldsDef = \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type_class] }} },\n {% end %}\n {% end %}\n\n }\n\n \n# --------------------------------------------------------------------------\n\n\n \n# Creates a new `\n{{ model_class }}\n` instance.\n\n \n# > Useful to create (insert) a new entry in the DB.\n\n def initialize(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @{{ dec[:name] }} : {{ dec[:type] }} = {{ dec[:default] }},\n {% end %}\n {% end %}\n\n )\n \nend\n\n \n# Creates a new _strict_ `\n{{ model_class }}\n` instance without using default value.\n\n \n# > Can be populated with data from the DB.\n\n def self.new_strict(\n \n{% args = [] of ASTNode %}\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }} : {{ dec[:type] }},\n {% args << dec[:name] %}\n {% end %}\n {% end %}\n\n )\n \n{{ model_class }}\n::Schema.new(\n{{ args.splat }}\n)\n \nend\n\n private def self.process_next_rel(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n schema : \n{{ model_class }}\n::Schema,\n rel_idx : Int32,\n cols_readed : Int32\n )\n next_rel = relations[rel_idx]\n\n case next_rel[:name]\n \n{% for path, dec in model_relations %}\n {% if model_class == dec[:from_model] %}\n when {{ dec[:name] }}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} : {{ dec[:model_class] }}::Schema? = nil\n\n {% if dec[:has_many] %}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} = schema.{{ dec[:name].id }}.last?\n {% end %}\n\n if rel_schema = {{ dec[:model_class] }}::Schema.from_rs(\n rs,\n relations,\n rel_idx + 1, # move cursor to next rel\n cols_readed,\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }},\n )\n schema.{{ dec[:name].id }} {{ dec[:has_one] ? \"=\".id : \"<<\".id }} rel_schema.as({{ dec[:model_class] }}::Schema)\n end\n {% end %}\n {% end %}\n\n \nelse\n raise DBX::Error.new %(Cannot resolve the relation \"#{next_rel[:model_class]}.#{next_rel[:name]}\")\n \nend\n \nend\n\n \n# Creates an instance from a relation.\n\n def self.from_rs(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n rel_idx : Int32 = 0,\n cols_readed : Int32 = 0,\n last_schema : \n{{ model_class }}\n::Schema? = nil,\n ) : Schema?\n if relations.size == 0\n raise DBX::Error.new \"Bad method call. This method must be called only for a query with relation(s).\"\n \nend\n\n cols_total = rs.column_count\n\n \n{% cols_readed_initial = 0 %}\n\n\n \n# Fix: PG::ResultSet#read returned a String. A (Int64 | Nil) was expected.\n\n \n# Prevent this error when a resource is found without its relation(s) (like a conventional LEFT JOIN).\n\n should_not_read_first_field = false\n\n \n# first iter or try to check with pk for deep iter\n\n if !last_schema || cols_readed == 0 || \n{{ model_class }}\n.pk_name == rs.column_name(cols_readed)\n first_field = rs.read\n should_not_read_first_field = true\n \n{% cols_readed_initial += 1 %}\n\n return nil if first_field.nil?\n \nend\n\n schema = \n{{ model_class }}\n::Schema.new_strict(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: if should_not_read_first_field\n should_not_read_first_field = false\n first_field.as({{ dec[:type] }})\n else\n rs.read({{ dec[:type] }})\n end,\n {% cols_readed_initial += 1 %}\n {% end %}\n {% end %}\n\n )\n\n \n# avoid duplicate for deep iteration(s)\n\n if !last_schema.nil? && last_schema._ukey == schema._ukey\n schema = last_schema\n \nend\n\n cols_readed += \n{{ cols_readed_initial }}\n\n\n if rel_idx + 1 <= relations.size\n self.process_next_rel(rs, relations, schema, rel_idx, cols_readed)\n return schema\n \nend\n\n return schema if cols_total == cols_readed\n schema\n \nend\n\n \n# --------------------------------------------------------------------------\n\n\n def self.fields_def : FieldsDef\n \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type] }} },\n {% end %}\n {% end %}\n\n }\n \nend\n\n def self.relations_def : Hash(String, RelationDef)\n @@relations_def\n \nend\n\n def self.add_relation(path : String | Symbol, dec : RelationDef) : Schema.class\n full_path = \"\n{{ model_class }}\n.#{path}\"\n\n if @@relations_def.has_key?(full_path)\n raise DBX::Error.new %(relation \"#{full_path}\" already defined)\n \nend\n\n @@relations_def[full_path] = dec\n self\n \nend\n\n \n# Lookup the path in relations def.\n\n def self.lookup_relation_def?(path : Symbol | String) : \n{String, RelationDef?}\n model_name = \"#{model_class}\"\n path = path.to_s\n cursor_path = \"#{model_name}.#{path}\"\n\n if rel_found = @@relations_def[cursor_path]?\n return \n{ cursor_path, rel_found }\n \nend\n\n path_a = path.split(\".\")\n\n \n# not found above\n\n return \n{cursor_path, nil} if path_a.size == 1\n\n \n# lookup the rest\n\n cursor_path = \"#{model_name}.#{path_a.first}\"\n path_a.size.times do |i|\n next_part_i = i + 1\n\n if rel_found = @@relations_def[\"#{cursor_path}\"]?\n cursor_path = \"#{rel_found[:model_class]}.#{path_a[next_part_i]}\"\n \nend\n\n \n# if end of search\n\n break rel_found if path_a.size == next_part_i + 1\n \nend\n\n \n{cursor_path, rel_found}\n \nend\n\n \n# Find a relation from its path.\n\n def self.find_relation_from_path(path : String) : \n{\n relation: RelationDef,\n cursor_path: String,\n field: String,\n model: DBX::ORM::Model.class\n }\n raise DBX::Error.new \"Relation path is empty\" if path.empty?\n cursor_path, relation_def = self.lookup_relation_def?(path)\n\n \n# r_model is the rel_model if the path is not deep, ref_model for deep path\n\n unless relation_def && (r_model = relation_def[:model_class])\n parts = path.split('.')\n\n if parts.size > 2\n raise DBX::Error.new %(\n Relation path to long: \"#{path}\".\n The depth of a relationship selection cannot exceed 2 levels (max is \"#{parts[...-1].join(\".\")}\").\n PR is welcome ;-\\)\n )\n \nend\n\n raise DBX::Error.new %(Undefined relation \"#{path}\")\n \nend\n\n parts = path.split('.')\n\n \n# if not deep\n\n if parts.size == 1\n return \n{ relation: relation_def, cursor_path: cursor_path, field: path, model: r_model }\n \nend\n\n ref_model = r_model\n rel_field = parts.last\n\n \n{% i = 0 %}\n\n \n{% cond_start = \"if\".id %}\n\n \n{% for path, dec in RELATIONS %}\n {% i += 1 %}\n {% if i != 1 %}\n {% cond_start = \"elsif\".id %}\n {% end %}\n\n # if the model referant is found\n {{ cond_start }} ref_model == {{ dec[:from_model] }} && {{ dec[:name] }} == rel_field\n # relation model is resolved\n rel_model = {{ dec[:model_class] }}\n\n relation_def = {\n name: {{ dec[:name] }},\n model_class: {{ dec[:model_class] }},\n has_one: {{ dec[:has_one] }},\n has_many: {{ dec[:has_many] }}\n }\n {% end %}\n\n \n{{ \"end\".id }}\n \n# end: cond_start\n\n\n raise DBX::Error.new %(Model not found for relation path: \"#{path}\") unless rel_model\n\n \n{ relation: relation_def, cursor_path: cursor_path, field: rel_field, model: rel_model }\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaRelation","path":"DBX/ORM/SchemaRelation.html","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/relation.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"relation(var_decl,**opt)-macro","html_id":"relation(var_decl,**opt)-macro","name":"relation","doc":"Defines a relation.","summary":"

Defines a relation.

","abstract":false,"args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"args_string":"(var_decl, **opt)","location":{"filename":"src/orm/schema/def/relation.cr","line_number":10,"url":null},"def":{"name":"relation","args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"double_splat":{"name":"opt","doc":null,"default_value":"","external_name":"opt","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if var_decl.is_a?(TypeDeclaration) %}\n {% if var_decl.type.stringify.starts_with?(\"Array\")\n rel_model = var_decl.type.stringify[6...-1].id\n rel_schema_type = \"Array(#{rel_model}::Schema)\".id\n has_one = false\n has_many = true\nelse\n rel_model = var_decl.type\n rel_schema_type = \"#{rel_model}::Schema\".id\n has_one = true\n has_many = false\nend %}\n\n unless {{ var_decl.type }}.is_a?(DBX::ORM::Model.class) || {{ rel_model }}.is_a?(DBX::ORM::Model.class)\n raise \"{{ model_class }}: relation must be a Model class but is a {{ var_decl.type }}\"\n end\n\n {% RELATIONS[\"#{model_class}.#{var_decl.var}\"] = {name: \"#{var_decl.var}\", model_class: rel_model, from_model: model_class, has_one: has_one, has_many: has_many} %}\n\n self.add_relation(\"{{ var_decl.var }}\", {\n name: \"{{ var_decl.var }}\",\n model_class: {{ rel_model }},\n has_one: {{ has_one }},\n has_many: {{ has_many }},\n })\n\n @[JSON::Field(emit_null: false)]\n @[DB::Field(ignore: true)]\n @{{ var_decl.var }} : {{ rel_schema_type }}?\n\n def {{ var_decl.var }} : {{ rel_schema_type }}{% if has_one %}?{% end %}\n {% if has_many %}\n @{{ var_decl.var }} = [] of {{ rel_model }}::Schema unless @{{ var_decl.var }}\n return @{{ var_decl.var }}.not_nil!\n {% end %}\n\n @{{ var_decl.var }}\n end\n\n def {{ var_decl.var }}=(value : {{ rel_schema_type }})\n @{{ var_decl.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.relation doesn't support #{var_decl.class_name}\") %}\n {% end %}\n\n \n"}}],"types":[]}]},{"html_id":"dbx/DBX/Query","path":"DBX/Query.html","kind":"class","full_name":"DBX::Query","name":"Query","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/executor.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/ModelQuery","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query executor.\nSee also: https://crystal-lang.github.io/crystal-db/api/latest/DB/QueryMethods.html","summary":"

Query executor.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"build:Tuple-instance-method","html_id":"build:Tuple-instance-method","name":"build","doc":"Builds current query and returns `sql, args`.\nSee `DBX::QueryBuilder#build` method.","summary":"

Builds current query and returns sql, args.

","abstract":false,"args":[],"args_string":" : Tuple","args_html":" : Tuple","location":{"filename":"src/query_builder/executor.cr","line_number":170,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple","visibility":"Public","body":"@builder.build"}},{"id":"builder:DBX::QueryBuilder-instance-method","html_id":"builder:DBX::QueryBuilder-instance-method","name":"builder","doc":"Returns `DBX::QueryBuilder` instance used in current `Query` instance.","summary":"

Returns DBX::QueryBuilder instance used in current Query instance.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder","args_html":" : DBX::QueryBuilder","location":{"filename":"src/query_builder/executor.cr","line_number":175,"url":null},"def":{"name":"builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder","visibility":"Public","body":"@builder"}},{"id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {String, Int32},\n returning: {:name, :age}\n)\n# => {\"Baby\", 1}\n\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {name: String, age: Int32},\n returning: {:name, :age}\n)\n# => {name: \"Baby\", age: 1}\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/query_builder/executor.cr","line_number":198,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@adapter.create!(self, data, types, returning, pk_name, pk_type)"}},{"id":"exec-instance-method","html_id":"exec-instance-method","name":"exec","doc":":ditto:\nReturns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: Returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":42,"url":null},"def":{"name":"exec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n exec!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"exec!-instance-method","html_id":"exec!-instance-method","name":"exec!","doc":"Executes current built query that is expected to return an `DB::ExecResult`.","summary":"

Executes current built query that is expected to return an DB::ExecResult.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":22,"url":null},"def":{"name":"exec!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_method = @builder.query_method\nsql, args = @builder.build\ner = @db.exec(sql, args: args)\nif (((((query_method == (:insert)) || (query_method == (:update_one))) || (query_method == (:update))) || (query_method == (:delete_one))) || (query_method == (:delete))) && (er.rows_affected == 0)\n raise(DB::NoResultsError.new(\"DB::ExecResult: No rows affected\"))\nend\ner\n"}},{"id":"query-instance-method","html_id":"query-instance-method","name":"query","doc":"Executes current built query that is expected to return one or more results.\n\n```\ntests = [] of Array(String | Int32)\nrs = query.find(:tests).select(:name, :age).query\n\nbegin\n while rs.move_next\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nensure\n rs.close\nend\n```","summary":"

Executes current built query that is expected to return one or more results.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":64,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args)\n"}},{"id":"query(&)-instance-method","html_id":"query(&)-instance-method","name":"query","doc":"Executes current built query and yields a `DB::ResultSet` with the results.\nThe `DB::ResultSet` is closed automatically.\n\n```\ntests = [] of Array(String | Int32)\nquery.find(:tests).select(:name, :age).query do |rs|\n rs.each do\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nend\n```","summary":"

Executes current built query and yields a DB::ResultSet with the results.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":82,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_all(astypes)-instance-method","html_id":"query_all(astypes)-instance-method","name":"query_all","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":88,"url":null},"def":{"name":"query_all","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args, as: types)\n"}},{"id":"query_all(&)-instance-method","html_id":"query_all(&)-instance-method","name":"query_all","doc":"Executes current built query and yields a `DB::ResultSet` positioned\nat the beginning of each row, returning an `Array` of the values of the blocks.","summary":"

Executes current built query and yields a DB::ResultSet positioned at the beginning of each row, returning an Array of the values of the blocks.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":95,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_each(&)-instance-method","html_id":"query_each(&)-instance-method","name":"query_each","doc":"Executes current built query and yields the `DB::ResultSet` once per each row.","summary":"

Executes current built query and yields the DB::ResultSet once per each row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":101,"url":null},"def":{"name":"query_each","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_each(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_one(astypes)-instance-method","html_id":"query_one(astypes)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":114,"url":null},"def":{"name":"query_one","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one!(types)\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one(&)-instance-method","html_id":"query_one(&)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":129,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one! do |rs|\n yield rs\n end\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one!(astypes)-instance-method","html_id":"query_one!(astypes)-instance-method","name":"query_one!","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":107,"url":null},"def":{"name":"query_one!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args, as: types)\n"}},{"id":"query_one!(&)-instance-method","html_id":"query_one!(&)-instance-method","name":"query_one!","doc":"Executes current built query that expects at most a single row and yields\na `DB::ResultSet` positioned at that first row.","summary":"

Executes current built query that expects at most a single row and yields a DB::ResultSet positioned at that first row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":122,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"raw_query(&):Query-instance-method","html_id":"raw_query(&):Query-instance-method","name":"raw_query","doc":"See `DBX::QueryBuilder#query`","summary":"

See DBX::QueryBuilder#query

","abstract":false,"args":[],"args_string":"(&) : Query","args_html":"(&) : Query","location":{"filename":"src/query_builder/executor.cr","line_number":161,"url":null},"def":{"name":"raw_query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"Query","visibility":"Public","body":"@builder.query do\n with QueryBuilderScope.new(@builder) yield\nend\nself\n"}},{"id":"scalar-instance-method","html_id":"scalar-instance-method","name":"scalar","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.\nSo the type MUST be nillable:\n\n```\nquery\n .find(:tests)\n .select(:name)\n .where(:name, \"Terminator\")\n .scalar\n .as(String?)\n# => String | Nil\n```","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":154,"url":null},"def":{"name":"scalar","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n scalar!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"scalar!-instance-method","html_id":"scalar!-instance-method","name":"scalar!","doc":"Executes current built query and returns a single scalar value.","summary":"

Executes current built query and returns a single scalar value.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":136,"url":null},"def":{"name":"scalar!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.scalar(sql, args: args)\n"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as #query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":229,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a(&)-instance-method","html_id":"to_a(&)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(&block)`.","summary":"

Shortcut, same as #query_all(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":234,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all do |rs|\n yield rs\nend"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as #query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":214,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o(&)-instance-method","html_id":"to_o(&)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(&block)`.","summary":"

Shortcut, same as #query_one(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":224,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one do |rs|\n yield rs\nend"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as #query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":209,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!(&)-instance-method","html_id":"to_o!(&)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(&block)`.","summary":"

Shortcut, same as #query_one!(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":219,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one! do |rs|\n yield rs\nend"}}],"macros":[{"id":"method_missing(call)-macro","html_id":"method_missing(call)-macro","name":"method_missing","doc":null,"summary":null,"abstract":false,"args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"args_string":"(call)","location":{"filename":"src/query_builder/executor.cr","line_number":238,"url":null},"def":{"name":"method_missing","args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% if true %}\n {% if block = call.block %}\n # See `DBX::QueryBuilder#{{ call.name }}(&block` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }}) {{ block }}\n self\n end\n {% else %}\n # See `DBX::QueryBuilder#{{ call.name }}` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }})\n self\n end\n {% end %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/QueryBuilder","path":"DBX/QueryBuilder.html","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/builder.cr","line_number":9,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":10,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":9,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":"Quoting character.","summary":"

Quoting character.

"}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder"},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query builder.","summary":"

Query builder.

","class_methods":[],"constructors":[{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Creates a new `QueryBuilder`.","summary":"

Creates a new QueryBuilder.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_arg(value):String-instance-method","html_id":"add_arg(value):String-instance-method","name":"add_arg","doc":"Adds value to *args* and returns the `placeholder`.","summary":"

Adds value to args and returns the placeholder.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":49,"url":null},"def":{"name":"add_arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"if value.is_a?(Symbol)\n value = value.to_s\nend\n@args << value\nph(@args.size)\n"}},{"id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":58,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |_, value|\n add_arg(value)\nend"}},{"id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : Array, sep = ", ") : String","args_html":"(data : Array, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":63,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |value|\n add_arg(value)\nend"}},{"id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_kv_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a combined statement.\nExample: `field1 = $1, field2 = $2, field3 = $3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a combined statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":70,"url":null},"def":{"name":"add_args_and_kv_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |field, value|\n \"#{field} = #{add_arg(value)}\"\nend"}},{"id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":212,"url":null},"def":{"name":"alter","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"alter(command, field, data_type)\ntable(table)\n"}},{"id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(command : String, field : String, data_type = "") : QueryBuilder","args_html":"(command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":206,"url":null},"def":{"name":"alter","args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :alter\n@options = {command: command, field: field, data_type: data_type}\nself\n"}},{"id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"analyze\ntable(table)\n"}},{"id":"analyze:QueryBuilder-instance-method","html_id":"analyze:QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :analyze\nself\n"}},{"id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","name":"avg","doc":"Adds `AVG` to the current query.","summary":"

Adds AVG to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"avg","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"avg = \"AVG(#{field})\"\nif name.nil?\nelse\n avg = avg + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? avg : \"#{@select}, #{avg}\"\nself\n"}},{"id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","name":"between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":301,"url":null},"def":{"name":"between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nelse\n \" #{and_or} #{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nend)\nself\n"}},{"id":"build:SQLandArgsType-instance-method","html_id":"build:SQLandArgsType-instance-method","name":"build","doc":"Builds the current query and returns SQL (string) and arguments (array).\n\n```\nsql, args = builder.build\n```","summary":"

Builds the current query and returns SQL (string) and arguments (array).

","abstract":false,"args":[],"args_string":" : SQLandArgsType","args_html":" : SQLandArgsType","location":{"filename":"src/query_builder/builder.cr","line_number":34,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"SQLandArgsType","visibility":"Public","body":"{% if true %}\n case @query_method\n {% for method in [:find, :insert, :update, :delete, :drop, :alter, :query, :analyze, :check, :checksum, :optimize, :repair] %}\n when :{{ method.id }} then end_query(build_query_{{ method.id }})\n {% end %}\n when :update_one then end_query(build_query_update)\n when :delete_one then end_query(build_query_delete)\n else\n raise Error.new \"Bad QueryBuilder method. #{@query_method}\"\n end\n {% end %}"}},{"id":"check:QueryBuilder-instance-method","html_id":"check:QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :check\nself\n"}},{"id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"check\ntable(table)\n"}},{"id":"checksum:QueryBuilder-instance-method","html_id":"checksum:QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :checksum\nself\n"}},{"id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"checksum\ntable(table)\n"}},{"id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","name":"count","doc":"Adds `COUNT` to the current query.","summary":"

Adds COUNT to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"count","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"count = \"COUNT(#{field})\"\nif name.nil?\nelse\n count = count + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? count : \"#{@select}, #{count}\"\nself\n"}},{"id":"delete:QueryBuilder-instance-method","html_id":"delete:QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":165,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :delete\nself\n"}},{"id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":170,"url":null},"def":{"name":"delete","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\ntable(table)\n"}},{"id":"delete(pk_name,pk_value):QueryBuilder-instance-method","html_id":"delete(pk_name,pk_value):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":175,"url":null},"def":{"name":"delete","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\n@query_method = :delete_one\nself.where(pk_name, pk_value)\n"}},{"id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","html_id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":195,"url":null},"def":{"name":"drop","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"drop(check_exists)\ntable(table)\n"}},{"id":"drop(check_exists=true):QueryBuilder-instance-method","html_id":"drop(check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(check_exists = true) : QueryBuilder","args_html":"(check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":189,"url":null},"def":{"name":"drop","args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :drop\n@options = check_exists\nself\n"}},{"id":"find(pk_name,pk_value):QueryBuilder-instance-method","html_id":"find(pk_name,pk_value):QueryBuilder-instance-method","name":"find","doc":"Finds one resource by its primary key.\n\nSame as:\n\n```\nbuilder.find.where(pk_name, pk_value)\n```","summary":"

Finds one resource by its primary key.

","abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":101,"url":null},"def":{"name":"find","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find.where(pk_name, pk_value)"}},{"id":"find:QueryBuilder-instance-method","html_id":"find:QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":63,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :find\nself\n"}},{"id":"find(&):QueryBuilder-instance-method","html_id":"find(&):QueryBuilder-instance-method","name":"find","doc":"Adds `find` to current query\nand defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Adds #find to current query and defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":88,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\n@table = \"#{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"args_string":"(table_name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table_name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":68,"url":null},"def":{"name":"find","args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\ntable(table_name)\n"}},{"id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_join","doc":"Adds `FULL JOIN` to the current query.","summary":"

Adds FULL JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL\")"}},{"id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_outer_join","doc":"Adds `FULL OUTER JOIN` to the current query.","summary":"

Adds FULL OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL OUTER\")"}},{"id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"group_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"args_string":"(field : OneOrMoreFieldsType) : QueryBuilder","args_html":"(field : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":396,"url":null},"def":{"name":"group_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@group_by = field.is_a?(FieldsType) ? field.join(\", \") : field.to_s\nself\n"}},{"id":"having(&):QueryBuilder-instance-method","html_id":"having(&):QueryBuilder-instance-method","name":"having","doc":"Defines in raw form the SQL statement of `HAVING`.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(:tests).group_by(:payment).having { \"SUM(price) > 40\" }\n```\n\nGenerates:\n\n```\nSELECT * FROM tests GROUP_BY payment HAVING SUM(person) > 40\n```","summary":"

Defines in raw form the SQL statement of HAVING.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":425,"url":null},"def":{"name":"having","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"having","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":402,"url":null},"def":{"name":"having","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = if @operators.includes?(op_or_val.to_s)\n \"#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \"#{field} > #{add_arg(op_or_val)}\"\nend\nself\n"}},{"id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","name":"in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":275,"url":null},"def":{"name":"in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"keys = [] of String\nvalues.each do |val|\n keys << (add_arg(val))\nend\n@where = @where + (if @where.empty?\n \"#{field} #{type}IN (#{keys.join(\", \")})\"\nelse\n \" #{and_or} #{field} #{type}IN (#{keys.join(\", \")})\"\nend)\nself\n"}},{"id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"inner_join","doc":"Adds `INNER JOIN` to the current query.","summary":"

Adds INNER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"inner_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"INNER\")"}},{"id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":119,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :insert\n@data = to_data_h(data)\nself\n"}},{"id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":125,"url":null},"def":{"name":"insert","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"insert(data)\ntable(table)\n"}},{"id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","html_id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","name":"join","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":166,"url":null},"def":{"name":"join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + (if field2.nil?\n \" #{type} JOIN #{table} ON #{field1}\"\nelse\n \" #{type} JOIN #{table} ON #{field1} = #{field2}\"\nend)\nself\n"}},{"id":"join(&):QueryBuilder-instance-method","html_id":"join(&):QueryBuilder-instance-method","name":"join","doc":"Adds a raw `join` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").join { \"\n INNER JOIN T2 ON T1.a = T2.a\n AND T1.b = T2.b\n OR T1.b = #{q(some_value_to_quote)}\n\" }\n .join { \"LEFT JOIN payments p USING (product_id)\" }\n```","summary":"

Adds a raw #join to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":193,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"join:String-instance-method","html_id":"join:String-instance-method","name":"join","doc":"Returns jointure. Returns empty string if no jointure has been defined.\n\n```\nputs builder.join unless builder.join.blank? # or .empty?\n```","summary":"

Returns jointure.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":215,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@join"}},{"id":"last_query:String-instance-method","html_id":"last_query:String-instance-method","name":"last_query","doc":"Returns the last query.","summary":"

Returns the last query.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder.cr","line_number":295,"url":null},"def":{"name":"last_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@last_query"}},{"id":"last_query_method:Symbol?-instance-method","html_id":"last_query_method:Symbol?-instance-method","name":"last_query_method","doc":"Returns the last query method.","summary":"

Returns the last query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":300,"url":null},"def":{"name":"last_query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@last_query_method"}},{"id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_join","doc":"Adds `LEFT JOIN` to the current query.","summary":"

Adds LEFT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT\")"}},{"id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_outer_join","doc":"Adds `LEFT OUTER JOIN` to the current query.","summary":"

Adds LEFT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT OUTER\")"}},{"id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","name":"like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":322,"url":null},"def":{"name":"like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}LIKE #{add_arg(value)}\"\nelse\n \" #{and_or} #{field} #{type}LIKE #{add_arg(value)}\"\nend)\nself\n"}},{"id":"limit:String-instance-method","html_id":"limit:String-instance-method","name":"limit","doc":"Returns `limit` value. Returns empty string if no limit has been defined.\n\n```\nputs builder.limit unless builder.limit.blank? # or .empty?\n```","summary":"

Returns #limit value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":359,"url":null},"def":{"name":"limit","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@limit"}},{"id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","html_id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","name":"limit","doc":null,"summary":null,"abstract":false,"args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"args_string":"(limit, limit_end = nil) : QueryBuilder","args_html":"(limit, limit_end = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":343,"url":null},"def":{"name":"limit","args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if limit_end.nil?\n @limit = add_arg(limit)\nelse\n @limit = add_arg(limit_end)\n offset(limit)\nend\nself\n"}},{"id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","name":"max","doc":"Adds `MAX` to the current query.","summary":"

Adds MAX to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"max","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"max = \"MAX(#{field})\"\nif name.nil?\nelse\n max = max + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? max : \"#{@select}, #{max}\"\nself\n"}},{"id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","name":"min","doc":"Adds `MIN` to the current query.","summary":"

Adds MIN to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"min","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"min = \"MIN(#{field})\"\nif name.nil?\nelse\n min = min + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? min : \"#{@select}, #{min}\"\nself\n"}},{"id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":314,"url":null},"def":{"name":"not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"AND\")"}},{"id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":291,"url":null},"def":{"name":"not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"AND\")\nself\n"}},{"id":"not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"not_like(field:FieldType,value):QueryBuilder-instance-method","name":"not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":335,"url":null},"def":{"name":"not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"AND\")"}},{"id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":267,"url":null},"def":{"name":"not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"AND\")"}},{"id":"offset(offset):QueryBuilder-instance-method","html_id":"offset(offset):QueryBuilder-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"args_string":"(offset) : QueryBuilder","args_html":"(offset) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":363,"url":null},"def":{"name":"offset","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@offset = add_arg(offset)\nself\n"}},{"id":"offset:String-instance-method","html_id":"offset:String-instance-method","name":"offset","doc":"Returns `offset` value. Returns empty string if no offset has been defined.\n\n```\nputs builder.offset unless builder.offset.blank? # or .empty?\n```","summary":"

Returns #offset value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":373,"url":null},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset"}},{"id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"optimize\ntable(table)\n"}},{"id":"optimize:QueryBuilder-instance-method","html_id":"optimize:QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :optimize\nself\n"}},{"id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":310,"url":null},"def":{"name":"or_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"\", \"OR\")"}},{"id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":286,"url":null},"def":{"name":"or_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"\", \"OR\")\nself\n"}},{"id":"or_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":331,"url":null},"def":{"name":"or_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"\", \"OR\")"}},{"id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":318,"url":null},"def":{"name":"or_not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"OR\")"}},{"id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":296,"url":null},"def":{"name":"or_not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"OR\")\nself\n"}},{"id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":339,"url":null},"def":{"name":"or_not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"OR\")"}},{"id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":271,"url":null},"def":{"name":"or_not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"OR\")"}},{"id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":263,"url":null},"def":{"name":"or_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"\", \"OR\")"}},{"id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","html_id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","name":"order_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"args_string":"(field : FieldType, dir = nil) : QueryBuilder","args_html":"(field : FieldType, dir = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":384,"url":null},"def":{"name":"order_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"field = field.to_s\norder_by = if dir.nil?\n ( (field.includes?(\" \")) || (field == \"rand()\")) ? field : \"#{field} ASC\"\nelse\n \"#{field} #{dir.to_s.upcase}\"\nend\n@order_by = @order_by + (@order_by.empty? ? order_by : \", #{order_by}\")\nself\n"}},{"id":"paginate(per_page,page):QueryBuilder-instance-method","html_id":"paginate(per_page,page):QueryBuilder-instance-method","name":"paginate","doc":"Sets `offset` and `limit` to get pagination-compatible results.","summary":"

Sets #offset and #limit to get pagination-compatible results.

","abstract":false,"args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"args_string":"(per_page, page) : QueryBuilder","args_html":"(per_page, page) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":378,"url":null},"def":{"name":"paginate","args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@limit = add_arg(per_page)\n@offset = add_arg(((page > 0 ? page : 1) - 1) * per_page)\nself\n"}},{"id":"ph(position:Int):String-instance-method","html_id":"ph(position:Int):String-instance-method","name":"ph","doc":"Adds placeholder for a SQL argument.","summary":"

Adds placeholder for a SQL argument.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int) : String","args_html":"(position : Int) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":44,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@placeholder"}},{"id":"query(&):QueryBuilder-instance-method","html_id":"query(&):QueryBuilder-instance-method","name":"query","doc":"Generates a raw query.\n> Be careful, you have to manage arguments and quotes.\n\nExample:\n\n```\nputs builder.query { \"\n SELECT * FROM tests\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n LIMIT 1\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\nLIMIT 1\n```","summary":"

Generates a raw query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":284,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :query\n@query = \" #{with QueryBuilderScope.new(self) yield} \"\nself\n"}},{"id":"query_count:Int-instance-method","html_id":"query_count:Int-instance-method","name":"query_count","doc":"Returns number of queries made by the current instance.","summary":"

Returns number of queries made by the current instance.

","abstract":false,"args":[],"args_string":" : Int","args_html":" : Int","location":{"filename":"src/query_builder/builder.cr","line_number":310,"url":null},"def":{"name":"query_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int","visibility":"Public","body":"@query_count"}},{"id":"query_method:Symbol?-instance-method","html_id":"query_method:Symbol?-instance-method","name":"query_method","doc":"Returns the query method.","summary":"

Returns the query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":305,"url":null},"def":{"name":"query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@query_method"}},{"id":"quote(field:FieldType):String-instance-method","html_id":"quote(field:FieldType):String-instance-method","name":"quote","doc":"Wraps *field* with quotes (`QUOTE`).","summary":"

Wraps field with quotes (QUOTE).

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":39,"url":null},"def":{"name":"quote","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"\"#{QUOTE}#{field}#{QUOTE}\""}},{"id":"repair:QueryBuilder-instance-method","html_id":"repair:QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :repair\nself\n"}},{"id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"repair\ntable(table)\n"}},{"id":"reset_query-instance-method","html_id":"reset_query-instance-method","name":"reset_query","doc":"Resets current query.","summary":"

Resets current query.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"reset_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@query_method = nil\n@query = \"\"\n@data_kv = \"\"\n@data = nil\n@options = nil\n@returning = nil\n@args = [] of DBValue\n@select = \"*\"\n@table = \"\"\n@join = \"\"\n@where = \"\"\n@group_by = \"\"\n@having = \"\"\n@order_by = \"\"\n@limit = \"\"\n@offset = \"\"\nnil\n"}},{"id":"returning(*name:FieldType):QueryBuilder-instance-method","html_id":"returning(*name:FieldType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":450,"url":null},"def":{"name":"returning","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.returning(name)"}},{"id":"returning:String?-instance-method","html_id":"returning:String?-instance-method","name":"returning","doc":"Returns the SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

Returns the SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[],"args_string":" : String?","args_html":" : String?","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":456,"url":null},"def":{"name":"returning","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String | ::Nil","visibility":"Public","body":"@returning"}},{"id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":432,"url":null},"def":{"name":"returning","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if query_method == (:insert)\nelse\n raise(DBX::Error.new(\"\\\"returning\\\" method SHOULD be used only with \\\"insert\\\" statement.\"))\nend\n_fields = _build_selected_fields(fields)\n@returning = if @returning.nil? || ((@returning.not_nil!.compare(\"*\")) == 0)\n _fields\nelse\n \"#{@returning}, #{_fields}\"\nend\nself\n"}},{"id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_join","doc":"Adds `RIGHT JOIN` to the current query.","summary":"

Adds RIGHT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT\")"}},{"id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_outer_join","doc":"Adds `RIGHT OUTER JOIN` to the current query.","summary":"

Adds RIGHT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT OUTER\")"}},{"id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":136,"url":null},"def":{"name":"select","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"_fields = _build_selected_fields(fields)\n@select = (@select.compare(\"*\")) == 0 ? _fields : \"#{@select}, #{_fields}\"\nself\n"}},{"id":"select:String-instance-method","html_id":"select:String-instance-method","name":"select","doc":"Returns selected field(s). Default is `*`.\n\n```\nputs builder.select\n```","summary":"

Returns selected field(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":152,"url":null},"def":{"name":"select","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@select"}},{"id":"select(*name:FieldType):QueryBuilder-instance-method","html_id":"select(*name:FieldType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":143,"url":null},"def":{"name":"select","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.select(name)"}},{"id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","name":"sum","doc":"Adds `SUM` to the current query.","summary":"

Adds SUM to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"sum","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"sum = \"SUM(#{field})\"\nif name.nil?\nelse\n sum = sum + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? sum : \"#{@select}, #{sum}\"\nself\n"}},{"id":"table(&):QueryBuilder-instance-method","html_id":"table(&):QueryBuilder-instance-method","name":"table","doc":"Defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":97,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"table(*name:FieldType):QueryBuilder-instance-method","html_id":"table(*name:FieldType):QueryBuilder-instance-method","name":"table","doc":"Targets tables defined by variadic arguments.\n\n```\nbuilder.table(:table1, :table2)\n```","summary":"

Targets tables defined by variadic arguments.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":79,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"table(name)"}},{"id":"table:String-instance-method","html_id":"table:String-instance-method","name":"table","doc":"Returns table name(s). Returns empty string if no table has been defined.\n\n```\nputs builder.table unless builder.table.blank? # or .empty?\n```","summary":"

Returns table name(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":107,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@table"}},{"id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"table","doc":"Targets one or more tables.","summary":"

Targets one or more tables.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"args_string":"(name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":68,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = name.is_a?(FieldsType) ? name.join(\", \") : name.to_s\nself\n"}},{"id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","html_id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","name":"to_data_h","doc":"Converts `NamedTuple` to `DataHashType`.","summary":"

Converts NamedTuple to DataHashType.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : DataHashType","args_html":"(data : Hash | NamedTuple) : DataHashType","location":{"filename":"src/query_builder/builder.cr","line_number":23,"url":null},"def":{"name":"to_data_h","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DataHashType","visibility":"Public","body":"h = DataHashType.new\ndata.each do |k, v|\n h[k] = v\nend\nh\n"}},{"id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":137,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :update\nif data\nelse\n raise(Error.new(\"No data to update\"))\nend\n@data_kv = add_args_and_kv_from_data(to_data_h(data))\nself\n"}},{"id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":144,"url":null},"def":{"name":"update","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\ntable(table)\n"}},{"id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","args_html":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":149,"url":null},"def":{"name":"update","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\n@query_method = :update_one\nself.where(pk_name, pk_value)\n"}},{"id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","name":"where","doc":"Where clause.","summary":"

Where clause.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":224,"url":null},"def":{"name":"where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where = if @operators.includes?(op_or_val.to_s)\n \" #{type}#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \" #{type}#{field} = #{add_arg(op_or_val)}\"\nend\n@where = @where + (@where.empty? ? where : \" #{and_or}#{where}\")\nself\n"}},{"id":"where(&):QueryBuilder-instance-method","html_id":"where(&):QueryBuilder-instance-method","name":"where","doc":"Adds a raw `where` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").where { \"\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\n```","summary":"

Adds a raw #where to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":258,"url":null},"def":{"name":"where","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilder/ArgsType","path":"DBX/QueryBuilder/ArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::ArgsType","name":"ArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Argument(s) for SQL query.","summary":"

Argument(s) for SQL query.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DataHashType","path":"DBX/QueryBuilder/DataHashType.html","kind":"alias","full_name":"DBX::QueryBuilder::DataHashType","name":"DataHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type of the data `Hash`,\nused as a KV container for insert and update.","summary":"

The type of the data Hash, used as a KV container for insert and update.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DBValue","path":"DBX/QueryBuilder/DBValue.html","kind":"alias","full_name":"DBX::QueryBuilder::DBValue","name":"DBValue","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"DB Value.","summary":"

DB Value.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldsType","path":"DBX/QueryBuilder/FieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldsType","name":"FieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol))","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for several fields contained in an `Enumerable` (e.g: `Array` or `Tuple`).","summary":"

The type for several fields contained in an Enumerable (e.g: Array or Tuple).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldType","path":"DBX/QueryBuilder/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Field type.","summary":"

Field type.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/OneOrMoreFieldsType","path":"DBX/QueryBuilder/OneOrMoreFieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::OneOrMoreFieldsType","name":"OneOrMoreFieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":18,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol)","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for one or more fields.","summary":"

The type for one or more fields.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/SQLandArgsType","path":"DBX/QueryBuilder/SQLandArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::SQLandArgsType","name":"SQLandArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Tuple(String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil))","aliased_html":"{String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The return type of `build` method.","summary":"

The return type of build method.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/QueryBuilderScope","path":"DBX/QueryBuilderScope.html","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope","abstract":false,"superclass":{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"dbx/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/scope.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Handy `QueryBuilder` scope used into `Block`.","summary":"

Handy QueryBuilder scope used into Block.

","class_methods":[],"constructors":[{"id":"new(builder:QueryBuilder)-class-method","html_id":"new(builder:QueryBuilder)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"args_string":"(builder : QueryBuilder)","args_html":"(builder : QueryBuilder)","location":{"filename":"src/query_builder/scope.cr","line_number":13,"url":null},"def":{"name":"new","args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(builder)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"arg(value):String-instance-method","html_id":"arg(value):String-instance-method","name":"arg","doc":"Same as `QueryBuilder#add_arg`","summary":"

Same as QueryBuilder#add_arg

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/scope.cr","line_number":17,"url":null},"def":{"name":"arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.add_arg(value)"}},{"id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","html_id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"args_string":"(field : FieldType, io : IO::Memory) : IO::Memory","args_html":"(field : FieldType, io : IO::Memory) : IO::Memory","location":{"filename":"src/query_builder/scope.cr","line_number":22,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"IO::Memory","visibility":"Public","body":"@builder.quote(field, io)"}},{"id":"q(field:FieldType):String-instance-method","html_id":"q(field:FieldType):String-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/scope.cr","line_number":27,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.quote(field)"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilderScope/FieldType","path":"DBX/QueryBuilderScope/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilderScope::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/scope.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilderScope","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"dbx","body":"# :sparkles: DBX\n\n[![CI Status](https://github.com/Nicolab/crystal-dbx/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-dbx/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-dbx.svg)](https://github.com/Nicolab/crystal-dbx/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-dbx/)\n\n* DB connections manager\n* Query builder\n* ORM (alpha)\n\nDBX is a [Crystal lang](https://crystal-lang.org) module to query the database, built on top of [crystal-db](https://github.com/crystal-lang/crystal-db) (common API for DB drivers).\n\nDBX is designed in a decoupled way to embed only the necessary features (multi-connections manager, query builder, query executor and ORM).\n\n## Documentation\n\n* šŸš€ [Guide](/guide/README.md)\n* šŸ“˜ [API doc](https://nicolab.github.io/crystal-dbx/)\n* :bookmark_tabs: [Spec tests](https://github.com/Nicolab/crystal-dbx/tree/master/spec)\n\n## Contributing\n\n1. Fork it ().\n2. Create your feature branch (`git checkout -b my-new-feature`).\n3. See [Development](#Development).\n4. Commit your changes (`git commit -am 'Add some feature'`).\n5. Push to the branch (`git push origin my-new-feature`).\n6. Create a new Pull Request.\n\n### Development\n\n1. You only need Git, Docker and Docker-compose installed on your machine.\n2. Clone this repo and run `./scripts/prepare`.\n3. Run first `docker-compose up`,\n 1. then enter to container `docker-compose exec test_pg bash` (or `test_sqlite` service),\n 2. into the container `just dev-spec`.\n4. Check the project before committing or pushing, from the host: `./scripts/check`\n\nIt's just Docker and docker-compose, you can directly type all the commands Docker and docker-compose.\n\nāœØ Example:\n\n_Terminal 1_\n\n```sh\n# Start the dev stack\ndocker-compose up\n```\n\n_Terminal 2_\n\n```sh\n# enter in the test_pg container\ndocker-compose exec test_pg bash\n\n# then in the test_pg container\ncrystal run ./src/app.cr\n\n# or with a recipe (helper)\njust dev-spec # <= auto reload when the code change\n\n# recipe list\njust --list\n```\n\nAlso, quickly:\n\n* `docker-compose run --rm test_pg crystal spec`\n* or `docker-compose run --rm test_pg just dev-spec`\n* when you are done: `docker-compose down --remove-orphans`\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-dbx/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n* [Nicolas Talle (@Nicolab)](https://github.com/Nicolab) - Creator and maintainer.\n* Thanks to [@ilourt](https://github.com/ilourt) for the feedbacks and thoughts.\n* This project is useful to you? [Sponsor the developer](https://github.com/sponsors/Nicolab).\n","program":{"html_id":"dbx/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"dbx","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX","path":"DBX.html","kind":"module","full_name":"DBX","name":"DBX","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":60,"url":null},{"filename":"src/query_builder/builder.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":8,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":8,"url":null},{"filename":"src/query_builder/executor.cr","line_number":8,"url":null},{"filename":"src/query_builder/scope.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-dbx/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"DBX is a helper to handle multi DBs using the compatible drivers\nwith the common `crystal-db` module.\n\nExample with PostgreSQL:\n\n```\n# Connection URI / DSL https://www.postgresql.org/docs/current/libpq-connect.html#h5o-9\ndb = DBX.open(\"app\", \"postgres://...\", true)\n\npp DBX.db?(\"app\") ? \"defined\" : \"not defined\"\n\ndb.query \"select id, created_at, email from users\" do |rs|\n rs.each do\n id = rs.read(Int32)\n created_at = rs.read(Time)\n email = rs.read(String)\n puts \"##{id}: #{email} #{created_at}\"\n end\nend\n\n# Closes all connections of this DB connection pool and remove this DB connection pool.\nDBX.destroy(\"app\")\n```\n\nModel:\n\n```\nclass User\n include DBX::ORM::DSL\n\n field lang : String\n\n @[JSON::Field(key: \"firstName\")]\n field first_name : String?\nend\n\ndb = DBX.open \"app\", App.cfg.db_uri\n\nuser = User.from_rs(db.query(\"SELECT id, lang, first_name FROM users\"))\npp user.to_json\n\nuser = User.from_json \"{\\\"lang\\\":\\\"fr\\\",\\\"firstName\\\":\\\"Nico\\\"}\"\npp user\n```\n\nSee also `DBX::ORM` for a more advanced model system and query builder.\n\nResources:\n- https://crystal-lang.github.io/crystal-db/api/index.html\n- https://github.com/Nicolab/crystal-dbx/tree/master/guide","summary":"

DBX is a helper to handle multi DBs using the compatible drivers with the common crystal-db module.

","class_methods":[{"id":"db(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"db(name:String,uri:String,strict=false):DB::Database-class-method","name":"db","doc":"Same as `.open`.","summary":"

Same as .open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":92,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"self.open(name, uri, strict)"}},{"id":"db(name:String):DB::Database-class-method","html_id":"db(name:String):DB::Database-class-method","name":"db","doc":"Uses a given DB connection pool.","summary":"

Uses a given DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Database","args_html":"(name : String) : DB::Database","location":{"filename":"src/dbx.cr","line_number":87,"url":null},"def":{"name":"db","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"@@dbs[name]"}},{"id":"db?(name:String):Bool-class-method","html_id":"db?(name:String):Bool-class-method","name":"db?","doc":"Checks that a DB connection pool exists.","summary":"

Checks that a DB connection pool exists.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Bool","args_html":"(name : String) : Bool","location":{"filename":"src/dbx.cr","line_number":82,"url":null},"def":{"name":"db?","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@@dbs.has_key?(name)"}},{"id":"dbs:DBHashType-class-method","html_id":"dbs:DBHashType-class-method","name":"dbs","doc":"Returns all `DB::Database` instances.","summary":"

Returns all DB::Database instances.

","abstract":false,"args":[],"args_string":" : DBHashType","args_html":" : DBHashType","location":{"filename":"src/dbx.cr","line_number":77,"url":null},"def":{"name":"dbs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBHashType","visibility":"Public","body":"@@dbs"}},{"id":"destroy(name:String)-class-method","html_id":"destroy(name:String)-class-method","name":"destroy","doc":"Closes all connections of the DB connection pool *name*\nand remove the *name* DB connection pool.","summary":"

Closes all connections of the DB connection pool name and remove the name DB connection pool.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String)","args_html":"(name : String)","location":{"filename":"src/dbx.cr","line_number":112,"url":null},"def":{"name":"destroy","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @@dbs.has_key?(name)\n begin\n (self.db(name)).close\n rescue e : Exception\n puts(\"\\nšŸ‘» DBX.destroy: error caught when closing:\")\n pp(e)\n end\n @@dbs.delete(name)\nend"}},{"id":"destroy:Tuple(Int32,Int32)-class-method","html_id":"destroy:Tuple(Int32,Int32)-class-method","name":"destroy","doc":"Destroy all DB connection pool and and their connections.","summary":"

Destroy all DB connection pool and and their connections.

","abstract":false,"args":[],"args_string":" : Tuple(Int32, Int32)","args_html":" : Tuple(Int32, Int32)","location":{"filename":"src/dbx.cr","line_number":125,"url":null},"def":{"name":"destroy","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple(Int32, Int32)","visibility":"Public","body":"size = @@dbs.size\n@@dbs.each_key do |name|\n self.destroy(name)\nend\n{@@dbs.size, size}\n"}},{"id":"open(name:String,uri:String,strict=false):DB::Database-class-method","html_id":"open(name:String,uri:String,strict=false):DB::Database-class-method","name":"open","doc":"Ensures only once DB connection pool by *name* is open.\nIf the DB connection pool *name* is already initialized, it is returned.\nRaises an error if *strict* is *true* and the DB connection pool *name* is\nalready opened.","summary":"

Ensures only once DB connection pool by name is open.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"args_string":"(name : String, uri : String, strict = false) : DB::Database","args_html":"(name : String, uri : String, strict = false) : DB::Database","location":{"filename":"src/dbx.cr","line_number":100,"url":null},"def":{"name":"open","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"},{"name":"uri","doc":null,"default_value":"","external_name":"uri","restriction":"String"},{"name":"strict","doc":null,"default_value":"false","external_name":"strict","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"if @@dbs.has_key?(name)\n if strict\n else\n return @@dbs[name]\n end\n raise(\"'#{name}' DB connection pool is already opened\")\nend\n@@dbs[name] = DB.open(uri)\n"}},{"id":"pool_open_connections(name:String):Int32-class-method","html_id":"pool_open_connections(name:String):Int32-class-method","name":"pool_open_connections","doc":"Gets the number of the connections opened in the pool of *name*.","summary":"

Gets the number of the connections opened in the pool of name.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : Int32","args_html":"(name : String) : Int32","location":{"filename":"src/dbx.cr","line_number":142,"url":null},"def":{"name":"pool_open_connections","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"pool_stats = self.pool_stats(name)\nif pool_stats\nelse\n return 0\nend\npool_stats.open_connections\n"}},{"id":"pool_stats(name:String):DB::Pool::Stats?-class-method","html_id":"pool_stats(name:String):DB::Pool::Stats?-class-method","name":"pool_stats","doc":"Pool stats\nhttps://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html","summary":"

Pool stats https://crystal-lang.github.io/crystal-db/api/latest/DB/Pool.html

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"args_string":"(name : String) : DB::Pool::Stats?","args_html":"(name : String) : DB::Pool::Stats?","location":{"filename":"src/dbx.cr","line_number":137,"url":null},"def":{"name":"pool_stats","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Pool::Stats | ::Nil","visibility":"Public","body":"if self.db?(name)\n (self.db(name)).pool.stats\nend"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"around_query_or_exec(&block)-macro","html_id":"around_query_or_exec(&block)-macro","name":"around_query_or_exec","doc":"This macro allows injecting code to be run before and after the execution\nof the request. It should return the yielded value. It must be called with 1\nblock argument that will be used to pass the `args : Enumerable`.\nThis macro should be called at the top level, not from a method.\n\n> Be careful of the performance penalty that each hook may cause,\n be aware that your code will be executed at each query and exec.\n\n```\nDBX.around_query_or_exec do |args|\n puts \"before\"\n res = yield\n puts \"after\"\n\n puts res.class\n puts \"exec\" if res.is_a?(DB::ExecResult)\n puts \"query\" if res.is_a?(DB::ResultSet)\n\n puts \"with args:\"\n pp args\n\n res\nend\n```\n\nExample to measure query execution time:\n\n```\nDBX.around_query_or_exec do |args|\n start = Time.monotonic\n res = yield\n elapsed_time = Time.monotonic - start\n\n puts \"Query execution time: #{elapsed_time}\"\n res\nend\n```","summary":"

This macro allows injecting code to be run before and after the execution of the request.

","abstract":false,"args":[],"args_string":"(&block)","location":{"filename":"src/dbx.cr","line_number":185,"url":null},"def":{"name":"around_query_or_exec","args":[],"double_splat":null,"splat_index":null,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"visibility":"Public","body":" class ::DB::Statement\n def_around_query_or_exec do |args|\n \n{{ block.body }}\n\n \nend\n \nend\n \n"}}],"types":[{"html_id":"dbx/DBX/Adapter","path":"DBX/Adapter.html","kind":"module","full_name":"DBX::Adapter","name":"Adapter","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/adapter.cr","line_number":11,"url":null},{"filename":"src/adapter/pg.cr","line_number":12,"url":null},{"filename":"src/adapter/sqlite.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DB adapter(s) used by `DBX::QueryBuilder` and `DBX::ORM`.","summary":"

DB adapter(s) used by DBX::QueryBuilder and DBX::ORM.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"inject_pg-macro","html_id":"inject_pg-macro","name":"inject_pg","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/pg.cr","line_number":14,"url":null},"def":{"name":"inject_pg","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::PostgreSQL\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}},{"id":"inject_sqlite-macro","html_id":"inject_sqlite-macro","name":"inject_sqlite","doc":"Injects `adapter_class` method (example, it's used in the models).","summary":"

Injects adapter_class method (example, it's used in the models).

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/adapter/sqlite.cr","line_number":14,"url":null},"def":{"name":"inject_sqlite","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" alias AdapterDB = DBX::Adapter::SQLite\n protected class_getter adapter_class : DBX::Adapter::Base.class = AdapterDB\n "}}],"types":[{"html_id":"dbx/DBX/Adapter/Base","path":"DBX/Adapter/Base.html","kind":"class","full_name":"DBX::Adapter::Base","name":"Base","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/adapter.cr","line_number":13,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"}],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"Base adapter.","summary":"

Base adapter.

","class_methods":[{"id":"builder_class:QueryBuilder.class-class-method","html_id":"builder_class:QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class.","summary":"

Returns query builder class.

","abstract":false,"args":[],"args_string":" : QueryBuilder.class","args_html":" : QueryBuilder.class","location":{"filename":"src/adapter/adapter.cr","line_number":34,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder.class","visibility":"Public","body":"raise(NotImplementedError.new(\"'#{self}' model MUST define '#{self}.builder_class' method.\"))"}},{"id":"new_builder:QueryBuilder-class-method","html_id":"new_builder:QueryBuilder-class-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":29,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"constructors":[{"id":"new(db:DB::Database)-class-method","html_id":"new(db:DB::Database)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"args_string":"(db : DB::Database)","args_html":"(db : DB::Database)","location":{"filename":"src/adapter/adapter.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"db","doc":null,"default_value":"","external_name":"db","restriction":"DB::Database"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(db)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":true,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/adapter.cr","line_number":42,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"db:DB::Database-instance-method","html_id":"db:DB::Database-instance-method","name":"db","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/adapter/adapter.cr","line_number":19,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@db"}},{"id":"new_builder:QueryBuilder-instance-method","html_id":"new_builder:QueryBuilder-instance-method","name":"new_builder","doc":"Returns a new query builder instance.","summary":"

Returns a new query builder instance.

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/adapter/adapter.cr","line_number":24,"url":null},"def":{"name":"new_builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.builder_class.new"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","path":"DBX/Adapter/PGQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":58,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for PostgreSQL.\n:inherit:","summary":"

QueryBuilder for PostgreSQL.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"ph(position:Int)-instance-method","html_id":"ph(position:Int)-instance-method","name":"ph","doc":"Adds placeholder specific to PostgreSQL.\nAdds placeholder for a SQL argument.","summary":"

Adds placeholder specific to PostgreSQL.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int)","args_html":"(position : Int)","location":{"filename":"src/adapter/pg.cr","line_number":65,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"#{@placeholder}#{position}\""}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/Adapter/PostgreSQL","path":"DBX/Adapter/PostgreSQL.html","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/pg.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"PostgreSQL adapter","summary":"

PostgreSQL adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for PostgreSQL.","summary":"

Returns query builder class adapted for PostgreSQL.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/pg.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"PostgreSQL::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.\n> To get recorded data, PostgreSQL adapter use `RETURNING` SQL statement.\n *pk_name* and *pk_type* are useless and ignored,\n thanks PostgreSQL `RETURNING` that makes it simpler and more efficient :)","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/pg.cr","line_number":37,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create\\\" only, without other statement except the table. \\\"Test.create\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\n((query.insert(data)).returning(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/PostgreSQL/QueryBuilder","path":"DBX/Adapter/PostgreSQL/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::PostgreSQL::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/pg.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::PGQueryBuilder","aliased_html":"DBX::Adapter::PGQueryBuilder","const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/PostgreSQL","kind":"class","full_name":"DBX::Adapter::PostgreSQL","name":"PostgreSQL"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLite","path":"DBX/Adapter/SQLite.html","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite","abstract":false,"superclass":{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},"ancestors":[{"html_id":"dbx/DBX/Adapter/Base","kind":"class","full_name":"DBX::Adapter::Base","name":"Base"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":20,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"SQLite adapter","summary":"

SQLite adapter

","class_methods":[{"id":"builder_class:DBX::QueryBuilder.class-class-method","html_id":"builder_class:DBX::QueryBuilder.class-class-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":29,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}}],"constructors":[],"instance_methods":[{"id":"builder_class:DBX::QueryBuilder.class-instance-method","html_id":"builder_class:DBX::QueryBuilder.class-instance-method","name":"builder_class","doc":"Returns query builder class adapted for SQLite.","summary":"

Returns query builder class adapted for SQLite.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder.class","args_html":" : DBX::QueryBuilder.class","location":{"filename":"src/adapter/sqlite.cr","line_number":24,"url":null},"def":{"name":"builder_class","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder.class","visibility":"Public","body":"SQLite::QueryBuilder"}},{"id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(query:DBX::Query,data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\nSee `DBX::Query#create!` for more details.","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(query : DBX::Query, data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/adapter/sqlite.cr","line_number":34,"url":null},"def":{"name":"create!","args":[{"name":"query","doc":null,"default_value":"","external_name":"query","restriction":"DBX::Query"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if query.builder.query_method.nil?\nelse\n raise(DBX::Error.new(\"\\\"create\\\" method MUST not be composed. Uses \\\"create!\\\" only, without other statement except the table. \\\"Test.create!\\\" ou \\\"query.table(:tests).create\\\".\"))\nend\ntable_name = query.builder.table.gsub(\"\\\"\", \"\")\nlast_id = (query.insert(data)).exec!.last_insert_id\nif last_id.nil?\n raise(DB::NoResultsError.new(\"Cannot create\"))\nend\n(((query.table(table_name)).find(pk_name, last_id)).select(returning)).query_one!(types)\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/Adapter/SQLite/QueryBuilder","path":"DBX/Adapter/SQLite/QueryBuilder.html","kind":"alias","full_name":"DBX::Adapter::SQLite::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":21,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"DBX::Adapter::SQLiteQueryBuilder","aliased_html":"DBX::Adapter::SQLiteQueryBuilder","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter/SQLite","kind":"class","full_name":"DBX::Adapter::SQLite","name":"SQLite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","path":"DBX/Adapter/SQLiteQueryBuilder.html","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder","abstract":false,"superclass":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"ancestors":[{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/adapter/sqlite.cr","line_number":69,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/Adapter","kind":"module","full_name":"DBX::Adapter","name":"Adapter"},"doc":"`QueryBuilder` for SQLite.\n:inherit:","summary":"

QueryBuilder for SQLite.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/DBHashType","path":"DBX/DBHashType.html","kind":"alias","full_name":"DBX::DBHashType","name":"DBHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/dbx.cr","line_number":62,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, DB::Database)","aliased_html":"Hash(String, DB::Database)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/Error","path":"DBX/Error.html","kind":"class","full_name":"DBX::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":65,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/Model/Error","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when an error occurred, related with `DB` or `DBX`.","summary":"

Raised when an error occurred, related with DB or DBX.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/NotSupportedError","path":"DBX/NotSupportedError.html","kind":"class","full_name":"DBX::NotSupportedError","name":"NotSupportedError","abstract":false,"superclass":{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},"ancestors":[{"html_id":"dbx/NotImplementedError","kind":"class","full_name":"NotImplementedError","name":"NotImplementedError"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/dbx.cr","line_number":71,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Raised when a method is not supported.\n\nThis can be used either to stub out method bodies,\nor when the method is not supported on the current adapter.","summary":"

Raised when a method is not supported.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM","path":"DBX/ORM.html","kind":"module","full_name":"DBX::ORM","name":"ORM","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model.cr","line_number":8,"url":null},{"filename":"src/orm/model_mixin.cr","line_number":8,"url":null},{"filename":"src/orm/model_query.cr","line_number":8,"url":null},{"filename":"src/orm/orm.cr","line_number":18,"url":null},{"filename":"src/orm/schema/schema.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"DBX ORM (Object-Relational Mapping).","summary":"

DBX ORM (Object-Relational Mapping).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model","path":"DBX/ORM/Model.html","kind":"class","full_name":"DBX::ORM::Model","name":"Model","abstract":true,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":48,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Base class for all models.\n\nExample, creation of a model for a table `users`:\n\n```\nclass User < DBX::ORM::Model\n adapter :pg\n\n class Schema # < DBX::ORM::Schema#(User)\n field id : Int64?\n field name : String\n field about : String\n field age : Int32\n end\nend\n```\n\nCustomize `ModelQuery` used by `User` model:\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # Custom select\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Base class for all models.

","class_methods":[{"id":"connection:String-class-method","html_id":"connection:String-class-method","name":"connection","doc":"DB connection name used by this `Model` instance.","summary":"

DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/model.cr","line_number":176,"url":null},"def":{"name":"connection","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@conn_name"}},{"id":"db:DB::Database-class-method","html_id":"db:DB::Database-class-method","name":"db","doc":"Returns DB connection name used by this `Model` instance.","summary":"

Returns DB connection name used by this Model instance.

","abstract":false,"args":[],"args_string":" : DB::Database","args_html":" : DB::Database","location":{"filename":"src/orm/model.cr","line_number":181,"url":null},"def":{"name":"db","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DB::Database","visibility":"Public","body":"DBX.db(connection)"}},{"id":"models-class-method","html_id":"models-class-method","name":"models","doc":"Returns array of all non-abstract subclasses of *DBX::ORM::Model.\n\n```\nDBX::ORM::Model.models # => [Contact, Address, User]\n```","summary":"

Returns array of all non-abstract subclasses of *DBX::ORM::Model.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model.cr","line_number":190,"url":null},"def":{"name":"models","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% models = @type.all_subclasses.select do |m|\n !m.abstract?\nend %}\n {% if !models.empty? %}\n [\n {% for model in models %}\n ::{{ model.name }},\n {% end %}\n ]\n {% else %}\n [] of ::DBX::ORM::Model.class\n {% end %}\n {% end %}"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Model/Error","path":"DBX/ORM/Model/Error.html","kind":"class","full_name":"DBX::ORM::Model::Error","name":"Error","abstract":false,"superclass":{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},"ancestors":[{"html_id":"dbx/DBX/Error","kind":"class","full_name":"DBX::Error","name":"Error"},{"html_id":"dbx/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"dbx/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model.cr","line_number":53,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Model","kind":"class","full_name":"DBX::ORM::Model","name":"Model"},"doc":"Model error.","summary":"

Model error.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/ModelMixin","path":"DBX/ORM/ModelMixin.html","kind":"module","full_name":"DBX::ORM::ModelMixin(Model, ModelQuery)","name":"ModelMixin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/model_mixin.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Mixin for `Model` class.\n> Automatically injected into the models.","summary":"

Mixin for Model class.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","html_id":"create!(data:Hash|NamedTuple,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*"):Model::Schema-instance-method","name":"create!","doc":"Creates a new resource and returns.","summary":"

Creates a new resource and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","args_html":"(data : Hash | NamedTuple, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*") : Model::Schema","location":{"filename":"src/orm/model_mixin.cr","line_number":33,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Model::Schema","visibility":"Public","body":"query.create!(data, returning: returning)"}},{"id":"delete(pk_value):ModelQuery-instance-method","html_id":"delete(pk_value):ModelQuery-instance-method","name":"delete","doc":"Deletes one resource by its primary key.","summary":"

Deletes one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":56,"url":null},"def":{"name":"delete","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete(Model.pk_name, pk_value)"}},{"id":"delete:ModelQuery-instance-method","html_id":"delete:ModelQuery-instance-method","name":"delete","doc":"Deletes one or more resources.","summary":"

Deletes one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":51,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.delete"}},{"id":"find(pk_value):ModelQuery-instance-method","html_id":"find(pk_value):ModelQuery-instance-method","name":"find","doc":"Find one resource by its primary key.","summary":"

Find one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_value) : ModelQuery","args_html":"(pk_value) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":23,"url":null},"def":{"name":"find","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find(\"#{self.table_name}.#{Model.pk_name}\", pk_value)"}},{"id":"find:ModelQuery-instance-method","html_id":"find:ModelQuery-instance-method","name":"find","doc":"Find one or more resources.","summary":"

Find one or more resources.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":18,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.find"}},{"id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"insert(data:Hash|NamedTuple):ModelQuery-instance-method","name":"insert","doc":"Inserts a new resource.","summary":"

Inserts a new resource.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":28,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.insert(data)"}},{"id":"query:ModelQuery-instance-method","html_id":"query:ModelQuery-instance-method","name":"query","doc":"Creates a new `ModelQuery` instance.","summary":"

Creates a new ModelQuery instance.

","abstract":false,"args":[],"args_string":" : ModelQuery","args_html":" : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":13,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"(ModelQuery.new(self.adapter)).table(self.table_name)"}},{"id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(pk_value,data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Updates one resource by its primary key.","summary":"

Updates one resource by its primary key.

","abstract":false,"args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_value, data : Hash | NamedTuple) : ModelQuery","args_html":"(pk_value, data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":46,"url":null},"def":{"name":"update","args":[{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(Model.pk_name, pk_value, data)"}},{"id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","html_id":"update(data:Hash|NamedTuple):ModelQuery-instance-method","name":"update","doc":"Update one or more resources.","summary":"

Update one or more resources.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : ModelQuery","args_html":"(data : Hash | NamedTuple) : ModelQuery","location":{"filename":"src/orm/model_mixin.cr","line_number":41,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery","visibility":"Public","body":"query.update(data)"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/ModelQuery","path":"DBX/ORM/ModelQuery.html","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery","abstract":false,"superclass":{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},"ancestors":[{"html_id":"dbx/DBX/Query","kind":"class","full_name":"DBX::Query","name":"Query"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/model_query.cr","line_number":35,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"Generic `ModelQuery` class.\n> Automatically injected into the models.\n\nIf you want to customize the queries of a model, you can define\nyou own `ModelQuery` into this model.\n\n```\nclass User < DBX::ORM::Model\n # ...\n\n class ModelQuery < DBX::ORM::ModelQuery(User)\n # A custom `select`\n def select_custom\n self.select({:id, :name, :about, :age})\n end\n end\nend\n```\n\nIn the model example above, we have added a new method (`select_custom`) to `ModelQuery',\nwhich can be used in each query.\n\n```\nuser = User.find(id).select_custom.to_o\nusers = User.find.select_custom.to_a\n```","summary":"

Generic ModelQuery class.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = ModelQuery(Model).allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","html_id":"create!(data,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*")-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\ntest = Test.create!(data)\nputs test.id\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"args_string":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","args_html":"(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")","location":{"filename":"src/orm/model_query.cr","line_number":129,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"create!(data, as: Model::Schema, returning: returning, pk_name: Model.pk_name, pk_type: Model.pk_type)"}},{"id":"query_all-instance-method","html_id":"query_all-instance-method","name":"query_all","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":152,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"query_one-instance-method","html_id":"query_one-instance-method","name":"query_one","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":140,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"query_one!-instance-method","html_id":"query_one!-instance-method","name":"query_one!","doc":"Executes current query using current `Model::Schema`.","summary":"

Executes current query using current Model::Schema.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":146,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}},{"id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"rel(path:Symbol|String,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"rel","doc":"Refers to the result of a join in a defined `relation` property path.\n\n```\nusers = User\n .find\n .rel(\"groups\")\n .left_join(\"groups\", \"groups.id\", \"users.group_id\")\n .to_a\n```","summary":"

Refers to the result of a join in a defined relation property path.

","abstract":false,"args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(path : Symbol | String, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":91,"url":null},"def":{"name":"rel","args":[{"name":"path","doc":null,"default_value":"","external_name":"path","restriction":"Symbol | String"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"r = Model::Schema.find_relation_from_path(path.to_s)\n@relations << r[:relation]\nselect_all.select_all(r[:model], table_alias)\n"}},{"id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","html_id":"select_all(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects the relation fields.\nThis method is automatically called by the methods related to the joins with a model class.","summary":"

Selects the relation fields.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":63,"url":null},"def":{"name":"select_all","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if selected_all?(model_class, table_alias)\n return self\nend\nif table_alias\n table_alias = table_alias.to_s\n sql_fields = model_class.schema_class.fields.join(\",\") do |_, field|\n \"#{table_alias}.#{field[:name]}\"\n end\nelse\n sql_fields = model_class.schema_class.sql_fields\nend\nself.select(sql_fields)\n@rel_fields_selected[\"#{model_class}=>#{table_alias}\"] = true\nself\n"}},{"id":"select_all:ModelQuery(Model)-instance-method","html_id":"select_all:ModelQuery(Model)-instance-method","name":"select_all","doc":"Selects all SQL fields.","summary":"

Selects all SQL fields.

","abstract":false,"args":[],"args_string":" : ModelQuery(Model)","args_html":" : ModelQuery(Model)","location":{"filename":"src/orm/model_query.cr","line_number":47,"url":null},"def":{"name":"select_all","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ModelQuery(Model)","visibility":"Public","body":"if @fields_selected\n return self\nend\nself.select(Model::Schema.sql_fields)\n@fields_selected = true\nself\n"}},{"id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","html_id":"selected_all?(model_class:DBX::ORM::Model.class,table_alias:String|Symbol|Nil=nil):Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the relation fields are selected, `false` otherwise.\nSee `select_rel_fields`","summary":"

Returns true if the relation fields are selected, false otherwise.

","abstract":false,"args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"args_string":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","args_html":"(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool","location":{"filename":"src/orm/model_query.cr","line_number":57,"url":null},"def":{"name":"selected_all?","args":[{"name":"model_class","doc":null,"default_value":"","external_name":"model_class","restriction":"DBX::ORM::Model.class"},{"name":"table_alias","doc":null,"default_value":"nil","external_name":"table_alias","restriction":"String | Symbol | Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@rel_fields_selected.has_key?(\"#{model_class}=>#{table_alias}\")"}},{"id":"selected_all?:Bool-instance-method","html_id":"selected_all?:Bool-instance-method","name":"selected_all?","doc":"Returns `true` if the model fields are selected, `false` otherwise.\nSee `select_all`","summary":"

Returns true if the model fields are selected, false otherwise.

","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/orm/model_query.cr","line_number":42,"url":null},"def":{"name":"selected_all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@fields_selected"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":188,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Shortcut, same as `query_all`.","summary":"

Shortcut, same as #query_all.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":182,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_all_with_rel\nend\nquery_all(as: Model::Schema)\n"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":177,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o-instance-method","html_id":"to_o-instance-method","name":"to_o","doc":"Shortcut, same as `query_one`.","summary":"

Shortcut, same as #query_one.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":166,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel\nend\nquery_one(as: Model::Schema)\n"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/orm/model_query.cr","line_number":172,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!-instance-method","html_id":"to_o!-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!`.","summary":"

Shortcut, same as #query_one!.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/model_query.cr","line_number":160,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @relations.size == 0\nelse\n return query_one_with_rel!\nend\nquery_one!(as: Model::Schema)\n"}}],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema","path":"DBX/ORM/Schema.html","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":14,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"FIELDS","name":"FIELDS","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null},{"id":"RELATIONS","name":"RELATIONS","value":"{} of String => ASTNode","doc":null,"summary":null}],"included_modules":[{"html_id":"dbx/DB/Mappable","kind":"module","full_name":"DB::Mappable","name":"Mappable"},{"html_id":"dbx/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields"},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"},{"html_id":"dbx/JSON/Serializable","kind":"module","full_name":"JSON::Serializable","name":"Serializable"},{"html_id":"dbx/JSON/Serializable/Unmapped","kind":"module","full_name":"JSON::Serializable::Unmapped","name":"Unmapped"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":"`Model` Schema.","summary":"

Model Schema.

","class_methods":[{"id":"fields:MetaFieldHash-class-method","html_id":"fields:MetaFieldHash-class-method","name":"fields","doc":"Returns all SQL fields definitions.","summary":"

Returns all SQL fields definitions.

","abstract":false,"args":[],"args_string":" : MetaFieldHash","args_html":" : MetaFieldHash","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"MetaFieldHash","visibility":"Public","body":"@@fields"}},{"id":"from_rs(rs:DB::ResultSet)-class-method","html_id":"from_rs(rs:DB::ResultSet)-class-method","name":"from_rs","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"from_rs","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n objs = Array(self).new\n rs.each do\n objs << (self.new(rs))\n end\n objs\nensure\n rs.close\nend"}},{"id":"sql_fields:String-class-method","html_id":"sql_fields:String-class-method","name":"sql_fields","doc":"Returns the SQL fields of the model separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_fields"}},{"id":"sql_rel_fields:String-class-method","html_id":"sql_rel_fields:String-class-method","name":"sql_rel_fields","doc":"Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).","summary":"

Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/orm/schema/schema.cr","line_number":69,"url":null},"def":{"name":"sql_rel_fields","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@@sql_rel_fields"}}],"constructors":[{"id":"new(rs:DB::ResultSet)-class-method","html_id":"new(rs:DB::ResultSet)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"args_string":"(rs : DB::ResultSet)","args_html":"(rs : DB::ResultSet)","location":{"filename":"src/orm/schema/schema.cr","line_number":22,"url":null},"def":{"name":"new","args":[{"name":"rs","doc":null,"default_value":"","external_name":"rs","restriction":"::DB::ResultSet"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"instance = allocate\ninstance.initialize(__set_for_db_serializable: rs)\nif instance.responds_to?(:finalize)\n GC.add_finalizer(instance)\nend\ninstance\n"}},{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"args_string":"(pull : JSON::PullParser)","args_html":"(pull : JSON::PullParser)","location":{"filename":"src/orm/schema/schema.cr","line_number":23,"url":null},"def":{"name":"new","args":[{"name":"pull","doc":null,"default_value":"","external_name":"pull","restriction":"::JSON::PullParser"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_from_json_pull_parser(pull)"}}],"instance_methods":[{"id":"_pk-instance-method","html_id":"_pk-instance-method","name":"_pk","doc":"Same as `_pk` but may return `nil` when the record hasn't been saved\ninstead of raising.","summary":"

Same as #_pk but may return nil when the record hasn't been saved instead of raising.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":40,"url":null},"def":{"name":"_pk","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.id"}},{"id":"_pk!-instance-method","html_id":"_pk!-instance-method","name":"_pk!","doc":"Always returns this record's primary key value, even when the primary key\nisn't named `_pk`.","summary":"

Always returns this record's primary key value, even when the primary key isn't named #_pk.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":32,"url":null},"def":{"name":"_pk!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk.not_nil!"}},{"id":"_ukey-instance-method","html_id":"_ukey-instance-method","name":"_ukey","doc":"Unique (virtual) key used to compare the uniqueness of models.\nBy default this method returns the primary key (`_pk`) value.\n\nThis method avoid to rely directly on the primary key in case there is none in\nthe structure of the SQL table (even if there should always be one).\nUsed in the relation algorithm.\nAlso, can be useful when there is a need to check the uniqueness in other cases.\n\nIf for some reason your model does not have a primary key,\nyou can override this method to return a unique result\nrelated to the fields in your table, for example:\n\n```\n@[DB::Field(ignore: true)]\n@[JSON::Field(ignore: true)]\ndef _ukey\n \"#{self.group_id}.#{self.user_id}\"\nend\n```","summary":"

Unique (virtual) key used to compare the uniqueness of models.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/orm/schema/schema.cr","line_number":65,"url":null},"def":{"name":"_ukey","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self._pk"}}],"macros":[],"types":[{"html_id":"dbx/DBX/ORM/Schema/MetaField","path":"DBX/ORM/Schema/MetaField.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaField","name":"MetaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":16,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String)","aliased_html":"{name: String, rel_name: String, sql: String, rel_sql: String}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/MetaFieldHash","path":"DBX/ORM/Schema/MetaFieldHash.html","kind":"alias","full_name":"DBX::ORM::Schema::MetaFieldHash","name":"MetaFieldHash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":17,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String, NamedTuple(name: String, rel_name: String, sql: String, rel_sql: String))","aliased_html":"Hash(String, {name: String, rel_name: String, sql: String, rel_sql: String})","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/ORM/Schema/RelationDef","path":"DBX/ORM/Schema/RelationDef.html","kind":"alias","full_name":"DBX::ORM::Schema::RelationDef","name":"RelationDef","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/schema.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"NamedTuple(name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool)","aliased_html":"{name: String, model_class: DBX::ORM::Model.class, has_many: Bool, has_one: Bool}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/ORM/SchemaField","path":"DBX/ORM/SchemaField.html","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/field.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"field(name)-macro","html_id":"field(name)-macro","name":"field","doc":"Defines a SQL field.","summary":"

Defines a SQL field.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"args_string":"(name)","location":{"filename":"src/orm/schema/def/field.cr","line_number":10,"url":null},"def":{"name":"field","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if name.is_a?(TypeDeclaration) %}\n {% full_name = \"#{model_class}.#{name.var}\"\nif FIELDS[full_name].nil?\n FIELDS[full_name] = HashLiteral(String, ASTNode).new\nend\nFIELDS[full_name] = {model: model_class, name: name.var, full_name: full_name.id, rel_name: \"__#{model_class}_#{name.var}\", type: name.type, type_class: \"#{name.type.is_a?(Union) ? \"(#{name.type})\".id : name.type}.class\".id, default: name.value || \"nil\".id}\n %}\n\n @{{ name.var }} : {{ name.type }}{% if name.value %} = {{ name.value }}{% end %}\n def {{ name.var }} : {{ name.type }}\n @{{ name.var }}\n end\n\n def {{ name.var }}=(value : {{ name.type }})\n @{{ name.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.field doesn't support \" + name.class_name) %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectFields","path":"DBX/ORM/SchemaInjectFields.html","kind":"module","full_name":"DBX::ORM::SchemaInjectFields","name":"SchemaInjectFields","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/inject_fields.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_fields-macro","html_id":"orm_schema_inject_fields-macro","name":"orm_schema_inject_fields","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_fields.cr","line_number":9,"url":null},"def":{"name":"orm_schema_inject_fields","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" @@fields : MetaFieldHash = MetaFieldHash.new\n @@sql_fields : String = \"\"\n @@sql_rel_fields : String = \"\"\n\n \n# Returns all SQL fields definitions.\n\n def self.fields : MetaFieldHash\n @@fields\n \nend\n\n \n# Returns the SQL fields of the model separated by a comma (table.column, ...).\n\n def self.sql_fields : String\n @@sql_fields\n \nend\n\n \n# Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).\n\n def self.sql_rel_fields : String\n @@sql_rel_fields\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","path":"DBX/ORM/SchemaInjectForFinal.html","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal","abstract":false,"superclass":null,"ancestors":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"locations":[{"filename":"src/orm/schema/inject_for_final.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[{"html_id":"dbx/DBX/ORM/SchemaField","kind":"module","full_name":"DBX::ORM::SchemaField","name":"SchemaField"},{"html_id":"dbx/DBX/ORM/SchemaRelation","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation"}],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/Schema","kind":"class","full_name":"DBX::ORM::Schema","name":"Schema"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"orm_schema_inject_for_final-macro","html_id":"orm_schema_inject_for_final-macro","name":"orm_schema_inject_for_final","doc":"Finish for the final `Schema` class.","summary":"

Finish for the final Schema class.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/orm/schema/inject_for_final.cr","line_number":13,"url":null},"def":{"name":"orm_schema_inject_for_final","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% model_relations = {} of Symbol => ASTNode %}\n\n\n \n{% for path, dec in RELATIONS %}\n {% if model_class == dec[:from_model] %}\n {% model_relations[path] = dec %}\n {% end %}\n {% end %}\n\n\n \n{% consts = @type.constants.map(&.symbolize) %}\n\n \n{% if consts.includes?(:DBValue) %}{% else %}\n alias DBValue = DBX::QueryBuilder::DBValue\n {% end %}\n\n\n \n# Returns model table name.\n\n def self.table_name : String\n model_class.table_name\n \nend\n\n \n# Returns model class.\n\n def self.model_class : \n{{ model_class }}\n.class\n \n{{ model_class }}\n\n \nend\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @@fields[{{ full_name }}] = {\n name: \"{{ dec[:name] }}\",\n rel_name: {{ dec[:rel_name] }},\n sql: \"#{table_name}.{{ dec[:name] }}\",\n rel_sql: \"#{table_name}.{{ dec[:name] }} AS {{ dec[:rel_name].id }}\"\n }\n {% end %}\n {% end %}\n\n\n @@sql_fields : String = self.fields.join(\",\") \n{ |_, f| f[:sql] }\n @@sql_rel_fields : String = self.fields.join(\",\") \n{ |_, f| f[:rel_sql] }\n\n \n# All DB fields of the `\n{{ model_class }}\n` model.\n\n alias FieldsDef = \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type_class] }} },\n {% end %}\n {% end %}\n\n }\n\n \n# --------------------------------------------------------------------------\n\n\n \n# Creates a new `\n{{ model_class }}\n` instance.\n\n \n# > Useful to create (insert) a new entry in the DB.\n\n def initialize(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n @{{ dec[:name] }} : {{ dec[:type] }} = {{ dec[:default] }},\n {% end %}\n {% end %}\n\n )\n \nend\n\n \n# Creates a new _strict_ `\n{{ model_class }}\n` instance without using default value.\n\n \n# > Can be populated with data from the DB.\n\n def self.new_strict(\n \n{% args = [] of ASTNode %}\n\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }} : {{ dec[:type] }},\n {% args << dec[:name] %}\n {% end %}\n {% end %}\n\n )\n \n{{ model_class }}\n::Schema.new(\n{{ args.splat }}\n)\n \nend\n\n private def self.process_next_rel(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n schema : \n{{ model_class }}\n::Schema,\n rel_idx : Int32,\n cols_readed : Int32\n )\n next_rel = relations[rel_idx]\n\n case next_rel[:name]\n \n{% for path, dec in model_relations %}\n {% if model_class == dec[:from_model] %}\n when {{ dec[:name] }}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} : {{ dec[:model_class] }}::Schema? = nil\n\n {% if dec[:has_many] %}\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }} = schema.{{ dec[:name].id }}.last?\n {% end %}\n\n if rel_schema = {{ dec[:model_class] }}::Schema.from_rs(\n rs,\n relations,\n rel_idx + 1, # move cursor to next rel\n cols_readed,\n {{ \"last_#{dec[:model_class]}_schema\".downcase.id }},\n )\n schema.{{ dec[:name].id }} {{ dec[:has_one] ? \"=\".id : \"<<\".id }} rel_schema.as({{ dec[:model_class] }}::Schema)\n end\n {% end %}\n {% end %}\n\n \nelse\n raise DBX::Error.new %(Cannot resolve the relation \"#{next_rel[:model_class]}.#{next_rel[:name]}\")\n \nend\n \nend\n\n \n# Creates an instance from a relation.\n\n def self.from_rs(\n rs : DB::ResultSet,\n relations : Array(RelationDef),\n rel_idx : Int32 = 0,\n cols_readed : Int32 = 0,\n last_schema : \n{{ model_class }}\n::Schema? = nil,\n ) : Schema?\n if relations.size == 0\n raise DBX::Error.new \"Bad method call. This method must be called only for a query with relation(s).\"\n \nend\n\n cols_total = rs.column_count\n\n \n{% cols_readed_initial = 0 %}\n\n\n \n# Fix: PG::ResultSet#read returned a String. A (Int64 | Nil) was expected.\n\n \n# Prevent this error when a resource is found without its relation(s) (like a conventional LEFT JOIN).\n\n should_not_read_first_field = false\n\n \n# first iter or try to check with pk for deep iter\n\n if !last_schema || cols_readed == 0 || \n{{ model_class }}\n.pk_name == rs.column_name(cols_readed)\n first_field = rs.read\n should_not_read_first_field = true\n \n{% cols_readed_initial += 1 %}\n\n return nil if first_field.nil?\n \nend\n\n schema = \n{{ model_class }}\n::Schema.new_strict(\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: if should_not_read_first_field\n should_not_read_first_field = false\n first_field.as({{ dec[:type] }})\n else\n rs.read({{ dec[:type] }})\n end,\n {% cols_readed_initial += 1 %}\n {% end %}\n {% end %}\n\n )\n\n \n# avoid duplicate for deep iteration(s)\n\n if !last_schema.nil? && last_schema._ukey == schema._ukey\n schema = last_schema\n \nend\n\n cols_readed += \n{{ cols_readed_initial }}\n\n\n if rel_idx + 1 <= relations.size\n self.process_next_rel(rs, relations, schema, rel_idx, cols_readed)\n return schema\n \nend\n\n return schema if cols_total == cols_readed\n schema\n \nend\n\n \n# --------------------------------------------------------------------------\n\n\n def self.fields_def : FieldsDef\n \n{\n \n{% for full_name, dec in FIELDS %}\n {% if dec[:model] == model_class %}\n {{ dec[:name] }}: { type: {{ dec[:type] }} },\n {% end %}\n {% end %}\n\n }\n \nend\n\n def self.relations_def : Hash(String, RelationDef)\n @@relations_def\n \nend\n\n def self.add_relation(path : String | Symbol, dec : RelationDef) : Schema.class\n full_path = \"\n{{ model_class }}\n.#{path}\"\n\n if @@relations_def.has_key?(full_path)\n raise DBX::Error.new %(relation \"#{full_path}\" already defined)\n \nend\n\n @@relations_def[full_path] = dec\n self\n \nend\n\n \n# Lookup the path in relations def.\n\n def self.lookup_relation_def?(path : Symbol | String) : \n{String, RelationDef?}\n model_name = \"#{model_class}\"\n path = path.to_s\n cursor_path = \"#{model_name}.#{path}\"\n\n if rel_found = @@relations_def[cursor_path]?\n return \n{ cursor_path, rel_found }\n \nend\n\n path_a = path.split(\".\")\n\n \n# not found above\n\n return \n{cursor_path, nil} if path_a.size == 1\n\n \n# lookup the rest\n\n cursor_path = \"#{model_name}.#{path_a.first}\"\n path_a.size.times do |i|\n next_part_i = i + 1\n\n if rel_found = @@relations_def[\"#{cursor_path}\"]?\n cursor_path = \"#{rel_found[:model_class]}.#{path_a[next_part_i]}\"\n \nend\n\n \n# if end of search\n\n break rel_found if path_a.size == next_part_i + 1\n \nend\n\n \n{cursor_path, rel_found}\n \nend\n\n \n# Find a relation from its path.\n\n def self.find_relation_from_path(path : String) : \n{\n relation: RelationDef,\n cursor_path: String,\n field: String,\n model: DBX::ORM::Model.class\n }\n raise DBX::Error.new \"Relation path is empty\" if path.empty?\n cursor_path, relation_def = self.lookup_relation_def?(path)\n\n \n# r_model is the rel_model if the path is not deep, ref_model for deep path\n\n unless relation_def && (r_model = relation_def[:model_class])\n parts = path.split('.')\n\n if parts.size > 2\n raise DBX::Error.new %(\n Relation path to long: \"#{path}\".\n The depth of a relationship selection cannot exceed 2 levels (max is \"#{parts[...-1].join(\".\")}\").\n PR is welcome ;-\\)\n )\n \nend\n\n raise DBX::Error.new %(Undefined relation \"#{path}\")\n \nend\n\n parts = path.split('.')\n\n \n# if not deep\n\n if parts.size == 1\n return \n{ relation: relation_def, cursor_path: cursor_path, field: path, model: r_model }\n \nend\n\n ref_model = r_model\n rel_field = parts.last\n\n \n{% i = 0 %}\n\n \n{% cond_start = \"if\".id %}\n\n \n{% for path, dec in RELATIONS %}\n {% i += 1 %}\n {% if i != 1 %}\n {% cond_start = \"elsif\".id %}\n {% end %}\n\n # if the model referant is found\n {{ cond_start }} ref_model == {{ dec[:from_model] }} && {{ dec[:name] }} == rel_field\n # relation model is resolved\n rel_model = {{ dec[:model_class] }}\n\n relation_def = {\n name: {{ dec[:name] }},\n model_class: {{ dec[:model_class] }},\n has_one: {{ dec[:has_one] }},\n has_many: {{ dec[:has_many] }}\n }\n {% end %}\n\n \n{% if i > 0 %}{{ \"end\".id }}{% end %}\n \n# end: cond_start\n\n\n raise DBX::Error.new %(Model not found for relation path: \"#{path}\") unless rel_model\n\n \n{ relation: relation_def, cursor_path: cursor_path, field: rel_field, model: rel_model }\n \nend\n \n"}}],"types":[]},{"html_id":"dbx/DBX/ORM/SchemaRelation","path":"DBX/ORM/SchemaRelation.html","kind":"module","full_name":"DBX::ORM::SchemaRelation","name":"SchemaRelation","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/orm/schema/def/relation.cr","line_number":8,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[{"html_id":"dbx/DBX/ORM/SchemaInjectForFinal","kind":"module","full_name":"DBX::ORM::SchemaInjectForFinal","name":"SchemaInjectForFinal"}],"namespace":{"html_id":"dbx/DBX/ORM","kind":"module","full_name":"DBX::ORM","name":"ORM"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"relation(var_decl,**opt)-macro","html_id":"relation(var_decl,**opt)-macro","name":"relation","doc":"Defines a relation.","summary":"

Defines a relation.

","abstract":false,"args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"args_string":"(var_decl, **opt)","location":{"filename":"src/orm/schema/def/relation.cr","line_number":10,"url":null},"def":{"name":"relation","args":[{"name":"var_decl","doc":null,"default_value":"","external_name":"var_decl","restriction":""}],"double_splat":{"name":"opt","doc":null,"default_value":"","external_name":"opt","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% model_class = (@type.class.stringify.gsub(/::Schema.class$/, \"\")).id %}\n\n \n{% if var_decl.is_a?(TypeDeclaration) %}\n {% if var_decl.type.stringify.starts_with?(\"Array\")\n rel_model = var_decl.type.stringify[6...-1].id\n rel_schema_type = \"Array(#{rel_model}::Schema)\".id\n has_one = false\n has_many = true\nelse\n rel_model = var_decl.type\n rel_schema_type = \"#{rel_model}::Schema\".id\n has_one = true\n has_many = false\nend %}\n\n unless {{ var_decl.type }}.is_a?(DBX::ORM::Model.class) || {{ rel_model }}.is_a?(DBX::ORM::Model.class)\n raise \"{{ model_class }}: relation must be a Model class but is a {{ var_decl.type }}\"\n end\n\n {% RELATIONS[\"#{model_class}.#{var_decl.var}\"] = {name: \"#{var_decl.var}\", model_class: rel_model, from_model: model_class, has_one: has_one, has_many: has_many} %}\n\n self.add_relation(\"{{ var_decl.var }}\", {\n name: \"{{ var_decl.var }}\",\n model_class: {{ rel_model }},\n has_one: {{ has_one }},\n has_many: {{ has_many }},\n })\n\n @[JSON::Field(emit_null: false)]\n @[DB::Field(ignore: true)]\n @{{ var_decl.var }} : {{ rel_schema_type }}?\n\n def {{ var_decl.var }} : {{ rel_schema_type }}{% if has_one %}?{% end %}\n {% if has_many %}\n @{{ var_decl.var }} = [] of {{ rel_model }}::Schema unless @{{ var_decl.var }}\n return @{{ var_decl.var }}.not_nil!\n {% end %}\n\n @{{ var_decl.var }}\n end\n\n def {{ var_decl.var }}=(value : {{ rel_schema_type }})\n @{{ var_decl.var }} = value\n end\n {% else %}\n {% raise(\"#{model_class}: DBX::ORM::Model.relation doesn't support #{var_decl.class_name}\") %}\n {% end %}\n\n \n"}}],"types":[]}]},{"html_id":"dbx/DBX/Query","path":"DBX/Query.html","kind":"class","full_name":"DBX::Query","name":"Query","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/executor.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/ORM/ModelQuery","kind":"class","full_name":"DBX::ORM::ModelQuery(Model)","name":"ModelQuery"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query executor.\nSee also: https://crystal-lang.github.io/crystal-db/api/latest/DB/QueryMethods.html","summary":"

Query executor.

","class_methods":[],"constructors":[{"id":"new(adapter:DBX::Adapter::Base)-class-method","html_id":"new(adapter:DBX::Adapter::Base)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"args_string":"(adapter : DBX::Adapter::Base)","args_html":"(adapter : DBX::Adapter::Base)","location":{"filename":"src/query_builder/executor.cr","line_number":16,"url":null},"def":{"name":"new","args":[{"name":"adapter","doc":null,"default_value":"","external_name":"adapter","restriction":"DBX::Adapter::Base"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(adapter)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"build:Tuple-instance-method","html_id":"build:Tuple-instance-method","name":"build","doc":"Builds current query and returns `sql, args`.\nSee `DBX::QueryBuilder#build` method.","summary":"

Builds current query and returns sql, args.

","abstract":false,"args":[],"args_string":" : Tuple","args_html":" : Tuple","location":{"filename":"src/query_builder/executor.cr","line_number":170,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Tuple","visibility":"Public","body":"@builder.build"}},{"id":"builder:DBX::QueryBuilder-instance-method","html_id":"builder:DBX::QueryBuilder-instance-method","name":"builder","doc":"Returns `DBX::QueryBuilder` instance used in current `Query` instance.","summary":"

Returns DBX::QueryBuilder instance used in current Query instance.

","abstract":false,"args":[],"args_string":" : DBX::QueryBuilder","args_html":" : DBX::QueryBuilder","location":{"filename":"src/query_builder/executor.cr","line_number":175,"url":null},"def":{"name":"builder","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DBX::QueryBuilder","visibility":"Public","body":"@builder"}},{"id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","html_id":"create!(data:Hash|NamedTuple,astypes,returning:DBX::QueryBuilder::OneOrMoreFieldsType="*",pk_name:DBX::QueryBuilder::FieldType=:id,pk_type=::Union(Int64,::Nil))-instance-method","name":"create!","doc":"Creates a new record and returns.\n\n```\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {String, Int32},\n returning: {:name, :age}\n)\n# => {\"Baby\", 1}\n\nquery.table(:tests).create!(\n {name: \"Baby\", about: \"I'm a baby\", age: 1},\n as: {name: String, age: Int32},\n returning: {:name, :age}\n)\n# => {name: \"Baby\", age: 1}\n```","summary":"

Creates a new record and returns.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"args_string":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","args_html":"(data : Hash | NamedTuple, as types, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*", pk_name : DBX::QueryBuilder::FieldType = :id, pk_type = ::Union(Int64, ::Nil))","location":{"filename":"src/query_builder/executor.cr","line_number":198,"url":null},"def":{"name":"create!","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"},{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""},{"name":"returning","doc":null,"default_value":"\"*\"","external_name":"returning","restriction":"DBX::QueryBuilder::OneOrMoreFieldsType"},{"name":"pk_name","doc":null,"default_value":":id","external_name":"pk_name","restriction":"DBX::QueryBuilder::FieldType"},{"name":"pk_type","doc":null,"default_value":"::Union(Int64, ::Nil)","external_name":"pk_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@adapter.create!(self, data, types, returning, pk_name, pk_type)"}},{"id":"exec-instance-method","html_id":"exec-instance-method","name":"exec","doc":":ditto:\nReturns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: Returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":42,"url":null},"def":{"name":"exec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n exec!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"exec!-instance-method","html_id":"exec!-instance-method","name":"exec!","doc":"Executes current built query that is expected to return an `DB::ExecResult`.","summary":"

Executes current built query that is expected to return an DB::ExecResult.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":22,"url":null},"def":{"name":"exec!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_method = @builder.query_method\nsql, args = @builder.build\ner = @db.exec(sql, args: args)\nif (((((query_method == (:insert)) || (query_method == (:update_one))) || (query_method == (:update))) || (query_method == (:delete_one))) || (query_method == (:delete))) && (er.rows_affected == 0)\n raise(DB::NoResultsError.new(\"DB::ExecResult: No rows affected\"))\nend\ner\n"}},{"id":"query-instance-method","html_id":"query-instance-method","name":"query","doc":"Executes current built query that is expected to return one or more results.\n\n```\ntests = [] of Array(String | Int32)\nrs = query.find(:tests).select(:name, :age).query\n\nbegin\n while rs.move_next\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nensure\n rs.close\nend\n```","summary":"

Executes current built query that is expected to return one or more results.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":64,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args)\n"}},{"id":"query(&)-instance-method","html_id":"query(&)-instance-method","name":"query","doc":"Executes current built query and yields a `DB::ResultSet` with the results.\nThe `DB::ResultSet` is closed automatically.\n\n```\ntests = [] of Array(String | Int32)\nquery.find(:tests).select(:name, :age).query do |rs|\n rs.each do\n name = rs.read(String)\n age = rs.read(Int32)\n tests << [name, age]\n end\nend\n```","summary":"

Executes current built query and yields a DB::ResultSet with the results.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":82,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_all(astypes)-instance-method","html_id":"query_all(astypes)-instance-method","name":"query_all","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":88,"url":null},"def":{"name":"query_all","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args, as: types)\n"}},{"id":"query_all(&)-instance-method","html_id":"query_all(&)-instance-method","name":"query_all","doc":"Executes current built query and yields a `DB::ResultSet` positioned\nat the beginning of each row, returning an `Array` of the values of the blocks.","summary":"

Executes current built query and yields a DB::ResultSet positioned at the beginning of each row, returning an Array of the values of the blocks.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":95,"url":null},"def":{"name":"query_all","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_all(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_each(&)-instance-method","html_id":"query_each(&)-instance-method","name":"query_each","doc":"Executes current built query and yields the `DB::ResultSet` once per each row.","summary":"

Executes current built query and yields the DB::ResultSet once per each row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":101,"url":null},"def":{"name":"query_each","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_each(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"query_one(astypes)-instance-method","html_id":"query_one(astypes)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":114,"url":null},"def":{"name":"query_one","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one!(types)\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one(&)-instance-method","html_id":"query_one(&)-instance-method","name":"query_one","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":129,"url":null},"def":{"name":"query_one","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n query_one! do |rs|\n yield rs\n end\nrescue DB::NoResultsError\n nil\nend"}},{"id":"query_one!(astypes)-instance-method","html_id":"query_one!(astypes)-instance-method","name":"query_one!","doc":"Executes current built query that is expected to return one result.","summary":"

Executes current built query that is expected to return one result.

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":107,"url":null},"def":{"name":"query_one!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args, as: types)\n"}},{"id":"query_one!(&)-instance-method","html_id":"query_one!(&)-instance-method","name":"query_one!","doc":"Executes current built query that expects at most a single row and yields\na `DB::ResultSet` positioned at that first row.","summary":"

Executes current built query that expects at most a single row and yields a DB::ResultSet positioned at that first row.

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":122,"url":null},"def":{"name":"query_one!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.query_one(sql, args: args) do |rs|\n yield rs\nend\n"}},{"id":"raw_query(&):Query-instance-method","html_id":"raw_query(&):Query-instance-method","name":"raw_query","doc":"See `DBX::QueryBuilder#query`","summary":"

See DBX::QueryBuilder#query

","abstract":false,"args":[],"args_string":"(&) : Query","args_html":"(&) : Query","location":{"filename":"src/query_builder/executor.cr","line_number":161,"url":null},"def":{"name":"raw_query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"Query","visibility":"Public","body":"@builder.query do\n with QueryBuilderScope.new(@builder) yield\nend\nself\n"}},{"id":"scalar-instance-method","html_id":"scalar-instance-method","name":"scalar","doc":":ditto:\nIf no result found, this method returns `nil` instead of raising `DB::NoResultsError`.\nSo the type MUST be nillable:\n\n```\nquery\n .find(:tests)\n .select(:name)\n .where(:name, \"Terminator\")\n .scalar\n .as(String?)\n# => String | Nil\n```","summary":"

:ditto: If no result found, this method returns nil instead of raising DB::NoResultsError.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":154,"url":null},"def":{"name":"scalar","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n scalar!\nrescue DB::NoResultsError\n nil\nend"}},{"id":"scalar!-instance-method","html_id":"scalar!-instance-method","name":"scalar!","doc":"Executes current built query and returns a single scalar value.","summary":"

Executes current built query and returns a single scalar value.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/executor.cr","line_number":136,"url":null},"def":{"name":"scalar!","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sql, args = @builder.build\n@db.scalar(sql, args: args)\n"}},{"id":"to_a(astypes)-instance-method","html_id":"to_a(astypes)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(types)`.","summary":"

Shortcut, same as #query_all(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":229,"url":null},"def":{"name":"to_a","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all(types)"}},{"id":"to_a(&)-instance-method","html_id":"to_a(&)-instance-method","name":"to_a","doc":"Shortcut, same as `query_all(&block)`.","summary":"

Shortcut, same as #query_all(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":234,"url":null},"def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_all do |rs|\n yield rs\nend"}},{"id":"to_o(astypes)-instance-method","html_id":"to_o(astypes)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(types)`.","summary":"

Shortcut, same as #query_one(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":214,"url":null},"def":{"name":"to_o","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one(types)"}},{"id":"to_o(&)-instance-method","html_id":"to_o(&)-instance-method","name":"to_o","doc":"Shortcut, same as `query_one(&block)`.","summary":"

Shortcut, same as #query_one(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":224,"url":null},"def":{"name":"to_o","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one do |rs|\n yield rs\nend"}},{"id":"to_o!(astypes)-instance-method","html_id":"to_o!(astypes)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(types)`.","summary":"

Shortcut, same as #query_one!(types).

","abstract":false,"args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"args_string":"(as types)","args_html":"(as types)","location":{"filename":"src/query_builder/executor.cr","line_number":209,"url":null},"def":{"name":"to_o!","args":[{"name":"types","doc":null,"default_value":"","external_name":"as","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one!(types)"}},{"id":"to_o!(&)-instance-method","html_id":"to_o!(&)-instance-method","name":"to_o!","doc":"Shortcut, same as `query_one!(&block)`.","summary":"

Shortcut, same as #query_one!(&block).

","abstract":false,"args":[],"args_string":"(&)","args_html":"(&)","location":{"filename":"src/query_builder/executor.cr","line_number":219,"url":null},"def":{"name":"to_o!","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"query_one! do |rs|\n yield rs\nend"}}],"macros":[{"id":"method_missing(call)-macro","html_id":"method_missing(call)-macro","name":"method_missing","doc":null,"summary":null,"abstract":false,"args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"args_string":"(call)","location":{"filename":"src/query_builder/executor.cr","line_number":238,"url":null},"def":{"name":"method_missing","args":[{"name":"call","doc":null,"default_value":"","external_name":"call","restriction":""}],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" \n{% if true %}\n {% if block = call.block %}\n # See `DBX::QueryBuilder#{{ call.name }}(&block` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }}) {{ block }}\n self\n end\n {% else %}\n # See `DBX::QueryBuilder#{{ call.name }}` method.\n def {{ call.name.id }}({{ call.args.splat }}) : DBX::Query\n @builder.{{ call.name.id }}({{ call.args.splat }})\n self\n end\n {% end %}\n {% end %}\n\n \n"}}],"types":[]},{"html_id":"dbx/DBX/QueryBuilder","path":"DBX/QueryBuilder.html","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder","abstract":false,"superclass":{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"dbx/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/builder.cr","line_number":9,"url":null},{"filename":"src/query_builder/builder_criteria.cr","line_number":10,"url":null},{"filename":"src/query_builder/builder_support.cr","line_number":9,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"QUOTE","name":"QUOTE","value":"'\"'","doc":"Quoting character.","summary":"

Quoting character.

"}],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"dbx/DBX/Adapter/PGQueryBuilder","kind":"class","full_name":"DBX::Adapter::PGQueryBuilder","name":"PGQueryBuilder"},{"html_id":"dbx/DBX/Adapter/SQLiteQueryBuilder","kind":"class","full_name":"DBX::Adapter::SQLiteQueryBuilder","name":"SQLiteQueryBuilder"}],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Query builder.","summary":"

Query builder.

","class_methods":[],"constructors":[{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Creates a new `QueryBuilder`.","summary":"

Creates a new QueryBuilder.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_arg(value):String-instance-method","html_id":"add_arg(value):String-instance-method","name":"add_arg","doc":"Adds value to *args* and returns the `placeholder`.","summary":"

Adds value to args and returns the placeholder.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":49,"url":null},"def":{"name":"add_arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"if value.is_a?(Symbol)\n value = value.to_s\nend\n@args << value\nph(@args.size)\n"}},{"id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":58,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |_, value|\n add_arg(value)\nend"}},{"id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","html_id":"add_args_and_fields_from_data(data:Array,sep=","):String-instance-method","name":"add_args_and_fields_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a listing statement.\nExample: `field1, field2, field3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a listing statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : Array, sep = ", ") : String","args_html":"(data : Array, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":63,"url":null},"def":{"name":"add_args_and_fields_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |value|\n add_arg(value)\nend"}},{"id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","html_id":"add_args_and_kv_from_data(data:NamedTuple|Hash,sep=","):String-instance-method","name":"add_args_and_kv_from_data","doc":"Extracts arguments and fields from data, populates `args`\nand returns SQL part for a combined statement.\nExample: `field1 = $1, field2 = $2, field3 = $3`","summary":"

Extracts arguments and fields from data, populates args and returns SQL part for a combined statement.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"args_string":"(data : NamedTuple | Hash, sep = ", ") : String","args_html":"(data : NamedTuple | Hash, sep = ", ") : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":70,"url":null},"def":{"name":"add_args_and_kv_from_data","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"NamedTuple | Hash"},{"name":"sep","doc":null,"default_value":"\", \"","external_name":"sep","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"data.join(sep) do |field, value|\n \"#{field} = #{add_arg(value)}\"\nend"}},{"id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(table:OneOrMoreFieldsType,command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":212,"url":null},"def":{"name":"alter","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"alter(command, field, data_type)\ntable(table)\n"}},{"id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","html_id":"alter(command:String,field:String,data_type=""):QueryBuilder-instance-method","name":"alter","doc":null,"summary":null,"abstract":false,"args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"args_string":"(command : String, field : String, data_type = "") : QueryBuilder","args_html":"(command : String, field : String, data_type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":206,"url":null},"def":{"name":"alter","args":[{"name":"command","doc":null,"default_value":"","external_name":"command","restriction":"String"},{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"String"},{"name":"data_type","doc":null,"default_value":"\"\"","external_name":"data_type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :alter\n@options = {command: command, field: field, data_type: data_type}\nself\n"}},{"id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"analyze(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"analyze\ntable(table)\n"}},{"id":"analyze:QueryBuilder-instance-method","html_id":"analyze:QueryBuilder-instance-method","name":"analyze","doc":"Builds the `ANALYZE` query","summary":"

Builds the ANALYZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"analyze","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :analyze\nself\n"}},{"id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"avg(field:FieldType,name=nil):QueryBuilder-instance-method","name":"avg","doc":"Adds `AVG` to the current query.","summary":"

Adds AVG to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"avg","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"avg = \"AVG(#{field})\"\nif name.nil?\nelse\n avg = avg + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? avg : \"#{@select}, #{avg}\"\nself\n"}},{"id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"between(field:FieldType,value1,value2,type="",and_or="AND"):QueryBuilder-instance-method","name":"between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value1, value2, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":301,"url":null},"def":{"name":"between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nelse\n \" #{and_or} #{field} #{type}BETWEEN #{add_arg(value1)} AND #{add_arg(value2)}\"\nend)\nself\n"}},{"id":"build:SQLandArgsType-instance-method","html_id":"build:SQLandArgsType-instance-method","name":"build","doc":"Builds the current query and returns SQL (string) and arguments (array).\n\n```\nsql, args = builder.build\n```","summary":"

Builds the current query and returns SQL (string) and arguments (array).

","abstract":false,"args":[],"args_string":" : SQLandArgsType","args_html":" : SQLandArgsType","location":{"filename":"src/query_builder/builder.cr","line_number":34,"url":null},"def":{"name":"build","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"SQLandArgsType","visibility":"Public","body":"{% if true %}\n case @query_method\n {% for method in [:find, :insert, :update, :delete, :drop, :alter, :query, :analyze, :check, :checksum, :optimize, :repair] %}\n when :{{ method.id }} then end_query(build_query_{{ method.id }})\n {% end %}\n when :update_one then end_query(build_query_update)\n when :delete_one then end_query(build_query_delete)\n else\n raise Error.new \"Bad QueryBuilder method. #{@query_method}\"\n end\n {% end %}"}},{"id":"check:QueryBuilder-instance-method","html_id":"check:QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :check\nself\n"}},{"id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"check(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"check","doc":"Builds the `CHECK` query","summary":"

Builds the CHECK query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"check","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"check\ntable(table)\n"}},{"id":"checksum:QueryBuilder-instance-method","html_id":"checksum:QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :checksum\nself\n"}},{"id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"checksum(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"checksum","doc":"Builds the `CHECKSUM` query","summary":"

Builds the CHECKSUM query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"checksum","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"checksum\ntable(table)\n"}},{"id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"count(field:FieldType,name=nil):QueryBuilder-instance-method","name":"count","doc":"Adds `COUNT` to the current query.","summary":"

Adds COUNT to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"count","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"count = \"COUNT(#{field})\"\nif name.nil?\nelse\n count = count + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? count : \"#{@select}, #{count}\"\nself\n"}},{"id":"delete:QueryBuilder-instance-method","html_id":"delete:QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":165,"url":null},"def":{"name":"delete","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :delete\nself\n"}},{"id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"delete(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":170,"url":null},"def":{"name":"delete","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\ntable(table)\n"}},{"id":"delete(pk_name,pk_value):QueryBuilder-instance-method","html_id":"delete(pk_name,pk_value):QueryBuilder-instance-method","name":"delete","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":175,"url":null},"def":{"name":"delete","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"delete\n@query_method = :delete_one\nself.where(pk_name, pk_value)\n"}},{"id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","html_id":"drop(table:OneOrMoreFieldsType,check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":195,"url":null},"def":{"name":"drop","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"drop(check_exists)\ntable(table)\n"}},{"id":"drop(check_exists=true):QueryBuilder-instance-method","html_id":"drop(check_exists=true):QueryBuilder-instance-method","name":"drop","doc":null,"summary":null,"abstract":false,"args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"args_string":"(check_exists = true) : QueryBuilder","args_html":"(check_exists = true) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":189,"url":null},"def":{"name":"drop","args":[{"name":"check_exists","doc":null,"default_value":"true","external_name":"check_exists","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :drop\n@options = check_exists\nself\n"}},{"id":"find(pk_name,pk_value):QueryBuilder-instance-method","html_id":"find(pk_name,pk_value):QueryBuilder-instance-method","name":"find","doc":"Finds one resource by its primary key.\n\nSame as:\n\n```\nbuilder.find.where(pk_name, pk_value)\n```","summary":"

Finds one resource by its primary key.

","abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"args_string":"(pk_name, pk_value) : QueryBuilder","args_html":"(pk_name, pk_value) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":101,"url":null},"def":{"name":"find","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find.where(pk_name, pk_value)"}},{"id":"find:QueryBuilder-instance-method","html_id":"find:QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":63,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :find\nself\n"}},{"id":"find(&):QueryBuilder-instance-method","html_id":"find(&):QueryBuilder-instance-method","name":"find","doc":"Adds `find` to current query\nand defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Adds #find to current query and defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":88,"url":null},"def":{"name":"find","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\n@table = \"#{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"find(table_name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"find","doc":null,"summary":null,"abstract":false,"args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"args_string":"(table_name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table_name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":68,"url":null},"def":{"name":"find","args":[{"name":"table_name","doc":null,"default_value":"","external_name":"table_name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"find\ntable(table_name)\n"}},{"id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_join","doc":"Adds `FULL JOIN` to the current query.","summary":"

Adds FULL JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL\")"}},{"id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"full_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"full_outer_join","doc":"Adds `FULL OUTER JOIN` to the current query.","summary":"

Adds FULL OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"full_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"FULL OUTER\")"}},{"id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"group_by(field:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"group_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"args_string":"(field : OneOrMoreFieldsType) : QueryBuilder","args_html":"(field : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":396,"url":null},"def":{"name":"group_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@group_by = field.is_a?(FieldsType) ? field.join(\", \") : field.to_s\nself\n"}},{"id":"having(&):QueryBuilder-instance-method","html_id":"having(&):QueryBuilder-instance-method","name":"having","doc":"Defines in raw form the SQL statement of `HAVING`.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(:tests).group_by(:payment).having { \"SUM(price) > 40\" }\n```\n\nGenerates:\n\n```\nSELECT * FROM tests GROUP_BY payment HAVING SUM(person) > 40\n```","summary":"

Defines in raw form the SQL statement of HAVING.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":425,"url":null},"def":{"name":"having","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"having(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"having","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":402,"url":null},"def":{"name":"having","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@having = if @operators.includes?(op_or_val.to_s)\n \"#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \"#{field} > #{add_arg(op_or_val)}\"\nend\nself\n"}},{"id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"in(field:FieldType,values:Array|Tuple,type="",and_or="AND"):QueryBuilder-instance-method","name":"in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":275,"url":null},"def":{"name":"in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"keys = [] of String\nvalues.each do |val|\n keys << (add_arg(val))\nend\n@where = @where + (if @where.empty?\n \"#{field} #{type}IN (#{keys.join(\", \")})\"\nelse\n \" #{and_or} #{field} #{type}IN (#{keys.join(\", \")})\"\nend)\nself\n"}},{"id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"inner_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"inner_join","doc":"Adds `INNER JOIN` to the current query.","summary":"

Adds INNER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"inner_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"INNER\")"}},{"id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":119,"url":null},"def":{"name":"insert","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :insert\n@data = to_data_h(data)\nself\n"}},{"id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"insert(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"insert","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":125,"url":null},"def":{"name":"insert","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"insert(data)\ntable(table)\n"}},{"id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","html_id":"join(table:FieldType,field1:FieldType,field2:FieldType?=nil,type=""):QueryBuilder-instance-method","name":"join","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil, type = "") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":166,"url":null},"def":{"name":"join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + (if field2.nil?\n \" #{type} JOIN #{table} ON #{field1}\"\nelse\n \" #{type} JOIN #{table} ON #{field1} = #{field2}\"\nend)\nself\n"}},{"id":"join(&):QueryBuilder-instance-method","html_id":"join(&):QueryBuilder-instance-method","name":"join","doc":"Adds a raw `join` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").join { \"\n INNER JOIN T2 ON T1.a = T2.a\n AND T1.b = T2.b\n OR T1.b = #{q(some_value_to_quote)}\n\" }\n .join { \"LEFT JOIN payments p USING (product_id)\" }\n```","summary":"

Adds a raw #join to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":193,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@join = @join + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}},{"id":"join:String-instance-method","html_id":"join:String-instance-method","name":"join","doc":"Returns jointure. Returns empty string if no jointure has been defined.\n\n```\nputs builder.join unless builder.join.blank? # or .empty?\n```","summary":"

Returns jointure.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":215,"url":null},"def":{"name":"join","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@join"}},{"id":"last_query:String-instance-method","html_id":"last_query:String-instance-method","name":"last_query","doc":"Returns the last query.","summary":"

Returns the last query.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder.cr","line_number":295,"url":null},"def":{"name":"last_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@last_query"}},{"id":"last_query_method:Symbol?-instance-method","html_id":"last_query_method:Symbol?-instance-method","name":"last_query_method","doc":"Returns the last query method.","summary":"

Returns the last query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":300,"url":null},"def":{"name":"last_query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@last_query_method"}},{"id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_join","doc":"Adds `LEFT JOIN` to the current query.","summary":"

Adds LEFT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT\")"}},{"id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"left_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"left_outer_join","doc":"Adds `LEFT OUTER JOIN` to the current query.","summary":"

Adds LEFT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"left_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"LEFT OUTER\")"}},{"id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"like(field:FieldType,value,type="",and_or="AND"):QueryBuilder-instance-method","name":"like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, value, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":322,"url":null},"def":{"name":"like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + (if @where.empty?\n \"#{field} #{type}LIKE #{add_arg(value)}\"\nelse\n \" #{and_or} #{field} #{type}LIKE #{add_arg(value)}\"\nend)\nself\n"}},{"id":"limit:String-instance-method","html_id":"limit:String-instance-method","name":"limit","doc":"Returns `limit` value. Returns empty string if no limit has been defined.\n\n```\nputs builder.limit unless builder.limit.blank? # or .empty?\n```","summary":"

Returns #limit value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":359,"url":null},"def":{"name":"limit","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@limit"}},{"id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","html_id":"limit(limit,limit_end=nil):QueryBuilder-instance-method","name":"limit","doc":null,"summary":null,"abstract":false,"args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"args_string":"(limit, limit_end = nil) : QueryBuilder","args_html":"(limit, limit_end = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":343,"url":null},"def":{"name":"limit","args":[{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":""},{"name":"limit_end","doc":null,"default_value":"nil","external_name":"limit_end","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if limit_end.nil?\n @limit = add_arg(limit)\nelse\n @limit = add_arg(limit_end)\n offset(limit)\nend\nself\n"}},{"id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"max(field:FieldType,name=nil):QueryBuilder-instance-method","name":"max","doc":"Adds `MAX` to the current query.","summary":"

Adds MAX to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"max","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"max = \"MAX(#{field})\"\nif name.nil?\nelse\n max = max + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? max : \"#{@select}, #{max}\"\nself\n"}},{"id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"min(field:FieldType,name=nil):QueryBuilder-instance-method","name":"min","doc":"Adds `MIN` to the current query.","summary":"

Adds MIN to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"min","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"min = \"MIN(#{field})\"\nif name.nil?\nelse\n min = min + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? min : \"#{@select}, #{min}\"\nself\n"}},{"id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":314,"url":null},"def":{"name":"not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"AND\")"}},{"id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":291,"url":null},"def":{"name":"not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"AND\")\nself\n"}},{"id":"not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"not_like(field:FieldType,value):QueryBuilder-instance-method","name":"not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":335,"url":null},"def":{"name":"not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"AND\")"}},{"id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":267,"url":null},"def":{"name":"not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"AND\")"}},{"id":"offset(offset):QueryBuilder-instance-method","html_id":"offset(offset):QueryBuilder-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"args_string":"(offset) : QueryBuilder","args_html":"(offset) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":363,"url":null},"def":{"name":"offset","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@offset = add_arg(offset)\nself\n"}},{"id":"offset:String-instance-method","html_id":"offset:String-instance-method","name":"offset","doc":"Returns `offset` value. Returns empty string if no offset has been defined.\n\n```\nputs builder.offset unless builder.offset.blank? # or .empty?\n```","summary":"

Returns #offset value.

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":373,"url":null},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset"}},{"id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"optimize(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"optimize\ntable(table)\n"}},{"id":"optimize:QueryBuilder-instance-method","html_id":"optimize:QueryBuilder-instance-method","name":"optimize","doc":"Builds the `OPTIMIZE` query","summary":"

Builds the OPTIMIZE query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"optimize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :optimize\nself\n"}},{"id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":310,"url":null},"def":{"name":"or_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"\", \"OR\")"}},{"id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":286,"url":null},"def":{"name":"or_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"\", \"OR\")\nself\n"}},{"id":"or_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":331,"url":null},"def":{"name":"or_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"\", \"OR\")"}},{"id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","html_id":"or_not_between(field:FieldType,value1,value2):QueryBuilder-instance-method","name":"or_not_between","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"args_string":"(field : FieldType, value1, value2) : QueryBuilder","args_html":"(field : FieldType, value1, value2) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":318,"url":null},"def":{"name":"or_not_between","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value1","doc":null,"default_value":"","external_name":"value1","restriction":""},{"name":"value2","doc":null,"default_value":"","external_name":"value2","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"between(field, value1, value2, \"NOT \", \"OR\")"}},{"id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","html_id":"or_not_in(field:FieldType,values:Array|Tuple):QueryBuilder-instance-method","name":"or_not_in","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"args_string":"(field : FieldType, values : Array | Tuple) : QueryBuilder","args_html":"(field : FieldType, values : Array | Tuple) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":296,"url":null},"def":{"name":"or_not_in","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array | Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.in(field, values, \"NOT \", \"OR\")\nself\n"}},{"id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","html_id":"or_not_like(field:FieldType,value):QueryBuilder-instance-method","name":"or_not_like","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(field : FieldType, value) : QueryBuilder","args_html":"(field : FieldType, value) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":339,"url":null},"def":{"name":"or_not_like","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"like(field, value, \"NOT \", \"OR\")"}},{"id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_not_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_not_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":271,"url":null},"def":{"name":"or_not_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"NOT \", \"OR\")"}},{"id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","html_id":"or_where(field:FieldType,op_or_val,value=nil):QueryBuilder-instance-method","name":"or_where","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":263,"url":null},"def":{"name":"or_where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where(field, op_or_val, value, \"\", \"OR\")"}},{"id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","html_id":"order_by(field:FieldType,dir=nil):QueryBuilder-instance-method","name":"order_by","doc":null,"summary":null,"abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"args_string":"(field : FieldType, dir = nil) : QueryBuilder","args_html":"(field : FieldType, dir = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":384,"url":null},"def":{"name":"order_by","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"dir","doc":null,"default_value":"nil","external_name":"dir","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"field = field.to_s\norder_by = if dir.nil?\n ( (field.includes?(\" \")) || (field == \"rand()\")) ? field : \"#{field} ASC\"\nelse\n \"#{field} #{dir.to_s.upcase}\"\nend\n@order_by = @order_by + (@order_by.empty? ? order_by : \", #{order_by}\")\nself\n"}},{"id":"paginate(per_page,page):QueryBuilder-instance-method","html_id":"paginate(per_page,page):QueryBuilder-instance-method","name":"paginate","doc":"Sets `offset` and `limit` to get pagination-compatible results.","summary":"

Sets #offset and #limit to get pagination-compatible results.

","abstract":false,"args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"args_string":"(per_page, page) : QueryBuilder","args_html":"(per_page, page) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":378,"url":null},"def":{"name":"paginate","args":[{"name":"per_page","doc":null,"default_value":"","external_name":"per_page","restriction":""},{"name":"page","doc":null,"default_value":"","external_name":"page","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@limit = add_arg(per_page)\n@offset = add_arg(((page > 0 ? page : 1) - 1) * per_page)\nself\n"}},{"id":"ph(position:Int):String-instance-method","html_id":"ph(position:Int):String-instance-method","name":"ph","doc":"Adds placeholder for a SQL argument.","summary":"

Adds placeholder for a SQL argument.

","abstract":false,"args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"args_string":"(position : Int) : String","args_html":"(position : Int) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":44,"url":null},"def":{"name":"ph","args":[{"name":"position","doc":null,"default_value":"","external_name":"position","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@placeholder"}},{"id":"query(&):QueryBuilder-instance-method","html_id":"query(&):QueryBuilder-instance-method","name":"query","doc":"Generates a raw query.\n> Be careful, you have to manage arguments and quotes.\n\nExample:\n\n```\nputs builder.query { \"\n SELECT * FROM tests\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n LIMIT 1\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\nLIMIT 1\n```","summary":"

Generates a raw query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":284,"url":null},"def":{"name":"query","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :query\n@query = \" #{with QueryBuilderScope.new(self) yield} \"\nself\n"}},{"id":"query_count:Int-instance-method","html_id":"query_count:Int-instance-method","name":"query_count","doc":"Returns number of queries made by the current instance.","summary":"

Returns number of queries made by the current instance.

","abstract":false,"args":[],"args_string":" : Int","args_html":" : Int","location":{"filename":"src/query_builder/builder.cr","line_number":310,"url":null},"def":{"name":"query_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int","visibility":"Public","body":"@query_count"}},{"id":"query_method:Symbol?-instance-method","html_id":"query_method:Symbol?-instance-method","name":"query_method","doc":"Returns the query method.","summary":"

Returns the query method.

","abstract":false,"args":[],"args_string":" : Symbol?","args_html":" : Symbol?","location":{"filename":"src/query_builder/builder.cr","line_number":305,"url":null},"def":{"name":"query_method","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Symbol | ::Nil","visibility":"Public","body":"@query_method"}},{"id":"quote(field:FieldType):String-instance-method","html_id":"quote(field:FieldType):String-instance-method","name":"quote","doc":"Wraps *field* with quotes (`QUOTE`).","summary":"

Wraps field with quotes (QUOTE).

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/builder_support.cr","line_number":39,"url":null},"def":{"name":"quote","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"\"#{QUOTE}#{field}#{QUOTE}\""}},{"id":"repair:QueryBuilder-instance-method","html_id":"repair:QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[],"args_string":" : QueryBuilder","args_html":" : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :repair\nself\n"}},{"id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"repair(table:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"repair","doc":"Builds the `REPAIR` query","summary":"

Builds the REPAIR query

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"args_string":"(table : OneOrMoreFieldsType) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":240,"url":null},"def":{"name":"repair","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"repair\ntable(table)\n"}},{"id":"reset_query-instance-method","html_id":"reset_query-instance-method","name":"reset_query","doc":"Resets current query.","summary":"

Resets current query.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":30,"url":null},"def":{"name":"reset_query","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@query_method = nil\n@query = \"\"\n@data_kv = \"\"\n@data = nil\n@options = nil\n@returning = nil\n@args = [] of DBValue\n@select = \"*\"\n@table = \"\"\n@join = \"\"\n@where = \"\"\n@group_by = \"\"\n@having = \"\"\n@order_by = \"\"\n@limit = \"\"\n@offset = \"\"\nnil\n"}},{"id":"returning(*name:FieldType):QueryBuilder-instance-method","html_id":"returning(*name:FieldType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":450,"url":null},"def":{"name":"returning","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.returning(name)"}},{"id":"returning:String?-instance-method","html_id":"returning:String?-instance-method","name":"returning","doc":"Returns the SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

Returns the SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[],"args_string":" : String?","args_html":" : String?","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":456,"url":null},"def":{"name":"returning","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String | ::Nil","visibility":"Public","body":"@returning"}},{"id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"returning(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"returning","doc":"SQL field(s) to be returned after an `insert` statement.\n> `*` (wildcard) means all fields.","summary":"

SQL field(s) to be returned after an #insert statement.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":432,"url":null},"def":{"name":"returning","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"if query_method == (:insert)\nelse\n raise(DBX::Error.new(\"\\\"returning\\\" method SHOULD be used only with \\\"insert\\\" statement.\"))\nend\n_fields = _build_selected_fields(fields)\n@returning = if @returning.nil? || ((@returning.not_nil!.compare(\"*\")) == 0)\n _fields\nelse\n \"#{@returning}, #{_fields}\"\nend\nself\n"}},{"id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_join","doc":"Adds `RIGHT JOIN` to the current query.","summary":"

Adds RIGHT JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT\")"}},{"id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","html_id":"right_outer_join(table:FieldType,field1:FieldType,field2:FieldType?=nil):QueryBuilder-instance-method","name":"right_outer_join","doc":"Adds `RIGHT OUTER JOIN` to the current query.","summary":"

Adds RIGHT OUTER JOIN to the current query.

","abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"args_string":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","args_html":"(table : FieldType, field1 : FieldType, field2 : FieldType? = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":198,"url":null},"def":{"name":"right_outer_join","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"FieldType"},{"name":"field1","doc":null,"default_value":"","external_name":"field1","restriction":"FieldType"},{"name":"field2","doc":null,"default_value":"nil","external_name":"field2","restriction":"FieldType | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"join(table, field1, field2, \"RIGHT OUTER\")"}},{"id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"select(fields:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"args_string":"(fields : OneOrMoreFieldsType) : QueryBuilder","args_html":"(fields : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":136,"url":null},"def":{"name":"select","args":[{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"_fields = _build_selected_fields(fields)\n@select = (@select.compare(\"*\")) == 0 ? _fields : \"#{@select}, #{_fields}\"\nself\n"}},{"id":"select:String-instance-method","html_id":"select:String-instance-method","name":"select","doc":"Returns selected field(s). Default is `*`.\n\n```\nputs builder.select\n```","summary":"

Returns selected field(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":152,"url":null},"def":{"name":"select","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@select"}},{"id":"select(*name:FieldType):QueryBuilder-instance-method","html_id":"select(*name:FieldType):QueryBuilder-instance-method","name":"select","doc":"Selects one or more fields.","summary":"

Selects one or more fields.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":143,"url":null},"def":{"name":"select","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"self.select(name)"}},{"id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","html_id":"sum(field:FieldType,name=nil):QueryBuilder-instance-method","name":"sum","doc":"Adds `SUM` to the current query.","summary":"

Adds SUM to the current query.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"args_string":"(field : FieldType, name = nil) : QueryBuilder","args_html":"(field : FieldType, name = nil) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":156,"url":null},"def":{"name":"sum","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"name","doc":null,"default_value":"nil","external_name":"name","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"sum = \"SUM(#{field})\"\nif name.nil?\nelse\n sum = sum + \" AS #{name}\"\nend\n@select = (@select.compare(\"*\")) == 0 ? sum : \"#{@select}, #{sum}\"\nself\n"}},{"id":"table(&):QueryBuilder-instance-method","html_id":"table(&):QueryBuilder-instance-method","name":"table","doc":"Defines in raw form the SQL statement of the table(s).\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find { \"#{q(\"posts\") AS p, articles a\" }\"\n```\n\nGenerates:\n\n```\nSELECT * FROM \"posts\" AS p, articles a\n```","summary":"

Defines in raw form the SQL statement of the table(s).

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":97,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = with QueryBuilderScope.new(self) yield\nself\n"}},{"id":"table(*name:FieldType):QueryBuilder-instance-method","html_id":"table(*name:FieldType):QueryBuilder-instance-method","name":"table","doc":"Targets tables defined by variadic arguments.\n\n```\nbuilder.table(:table1, :table2)\n```","summary":"

Targets tables defined by variadic arguments.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"args_string":"(*name : FieldType) : QueryBuilder","args_html":"(*name : FieldType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":79,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"FieldType"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"table(name)"}},{"id":"table:String-instance-method","html_id":"table:String-instance-method","name":"table","doc":"Returns table name(s). Returns empty string if no table has been defined.\n\n```\nputs builder.table unless builder.table.blank? # or .empty?\n```","summary":"

Returns table name(s).

","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":107,"url":null},"def":{"name":"table","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@table"}},{"id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","html_id":"table(name:OneOrMoreFieldsType):QueryBuilder-instance-method","name":"table","doc":"Targets one or more tables.","summary":"

Targets one or more tables.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"args_string":"(name : OneOrMoreFieldsType) : QueryBuilder","args_html":"(name : OneOrMoreFieldsType) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":68,"url":null},"def":{"name":"table","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":"OneOrMoreFieldsType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@table = name.is_a?(FieldsType) ? name.join(\", \") : name.to_s\nself\n"}},{"id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","html_id":"to_data_h(data:Hash|NamedTuple):DataHashType-instance-method","name":"to_data_h","doc":"Converts `NamedTuple` to `DataHashType`.","summary":"

Converts NamedTuple to DataHashType.

","abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : DataHashType","args_html":"(data : Hash | NamedTuple) : DataHashType","location":{"filename":"src/query_builder/builder.cr","line_number":23,"url":null},"def":{"name":"to_data_h","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"DataHashType","visibility":"Public","body":"h = DataHashType.new\ndata.each do |k, v|\n h[k] = v\nend\nh\n"}},{"id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(data : Hash | NamedTuple) : QueryBuilder","args_html":"(data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":137,"url":null},"def":{"name":"update","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@query_method = :update\nif data\nelse\n raise(Error.new(\"No data to update\"))\nend\n@data_kv = add_args_and_kv_from_data(to_data_h(data))\nself\n"}},{"id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(table:OneOrMoreFieldsType,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","args_html":"(table : OneOrMoreFieldsType, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":144,"url":null},"def":{"name":"update","args":[{"name":"table","doc":null,"default_value":"","external_name":"table","restriction":"OneOrMoreFieldsType"},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\ntable(table)\n"}},{"id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","html_id":"update(pk_name,pk_value,data:Hash|NamedTuple):QueryBuilder-instance-method","name":"update","doc":null,"summary":null,"abstract":false,"args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"args_string":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","args_html":"(pk_name, pk_value, data : Hash | NamedTuple) : QueryBuilder","location":{"filename":"src/query_builder/builder.cr","line_number":149,"url":null},"def":{"name":"update","args":[{"name":"pk_name","doc":null,"default_value":"","external_name":"pk_name","restriction":""},{"name":"pk_value","doc":null,"default_value":"","external_name":"pk_value","restriction":""},{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Hash | NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"update(data)\n@query_method = :update_one\nself.where(pk_name, pk_value)\n"}},{"id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","html_id":"where(field:FieldType,op_or_val,value=nil,type="",and_or="AND"):QueryBuilder-instance-method","name":"where","doc":"Where clause.","summary":"

Where clause.

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"args_string":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","args_html":"(field : FieldType, op_or_val, value = nil, type = "", and_or = "AND") : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":224,"url":null},"def":{"name":"where","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"op_or_val","doc":null,"default_value":"","external_name":"op_or_val","restriction":""},{"name":"value","doc":null,"default_value":"nil","external_name":"value","restriction":""},{"name":"type","doc":null,"default_value":"\"\"","external_name":"type","restriction":""},{"name":"and_or","doc":null,"default_value":"\"AND\"","external_name":"and_or","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"where = if @operators.includes?(op_or_val.to_s)\n \" #{type}#{field} #{op_or_val} #{add_arg(value)}\"\nelse\n \" #{type}#{field} = #{add_arg(op_or_val)}\"\nend\n@where = @where + (@where.empty? ? where : \" #{and_or}#{where}\")\nself\n"}},{"id":"where(&):QueryBuilder-instance-method","html_id":"where(&):QueryBuilder-instance-method","name":"where","doc":"Adds a raw `where` to current query.\n> Be careful, you have to manage arguments (`arg`) and quotes (`q`).\n\nExample:\n\n```\nbuilder.find(\"tests\").where { \"\n status = #{arg(true)}\n AND (\n #{q(:date)} <= #{arg(Time.utc - 1.day)}\n OR role = #{arg(:admin)}\n )\n\" }\n```\n\nGenerates:\n\n```text\nSELECT *\nFROM tests\nWHERE status = $1\nAND (\"date\" <= $2 OR role = $3)\n```","summary":"

Adds a raw #where to current query.

","abstract":false,"args":[],"args_string":"(&) : QueryBuilder","args_html":"(&) : QueryBuilder","location":{"filename":"src/query_builder/builder_criteria.cr","line_number":258,"url":null},"def":{"name":"where","args":[],"double_splat":null,"splat_index":null,"yields":0,"block_arg":null,"return_type":"QueryBuilder","visibility":"Public","body":"@where = @where + \" #{with QueryBuilderScope.new(self) yield}\"\nself\n"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilder/ArgsType","path":"DBX/QueryBuilder/ArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::ArgsType","name":"ArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Argument(s) for SQL query.","summary":"

Argument(s) for SQL query.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DataHashType","path":"DBX/QueryBuilder/DataHashType.html","kind":"alias","full_name":"DBX::QueryBuilder::DataHashType","name":"DataHashType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Hash(String | Symbol, Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type of the data `Hash`,\nused as a KV container for insert and update.","summary":"

The type of the data Hash, used as a KV container for insert and update.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/DBValue","path":"DBX/QueryBuilder/DBValue.html","kind":"alias","full_name":"DBX::QueryBuilder::DBValue","name":"DBValue","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)","aliased_html":"Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"DB Value.","summary":"

DB Value.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldsType","path":"DBX/QueryBuilder/FieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldsType","name":"FieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":15,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol))","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for several fields contained in an `Enumerable` (e.g: `Array` or `Tuple`).","summary":"

The type for several fields contained in an Enumerable (e.g: Array or Tuple).

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/FieldType","path":"DBX/QueryBuilder/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilder::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":12,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"Field type.","summary":"

Field type.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/OneOrMoreFieldsType","path":"DBX/QueryBuilder/OneOrMoreFieldsType.html","kind":"alias","full_name":"DBX::QueryBuilder::OneOrMoreFieldsType","name":"OneOrMoreFieldsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_criteria.cr","line_number":18,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol)","aliased_html":"Enumerable(String | Symbol) | Enumerable(String) | Enumerable(Symbol) | String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The type for one or more fields.","summary":"

The type for one or more fields.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"dbx/DBX/QueryBuilder/SQLandArgsType","path":"DBX/QueryBuilder/SQLandArgsType.html","kind":"alias","full_name":"DBX::QueryBuilder::SQLandArgsType","name":"SQLandArgsType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/builder_support.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"Tuple(String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil))","aliased_html":"{String, Enumerable(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | UUID | Nil)}","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilder","kind":"class","full_name":"DBX::QueryBuilder","name":"QueryBuilder"},"doc":"The return type of `build` method.","summary":"

The return type of build method.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"dbx/DBX/QueryBuilderScope","path":"DBX/QueryBuilderScope.html","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope","abstract":false,"superclass":{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"dbx/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"dbx/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"dbx/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/query_builder/scope.cr","line_number":10,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX","kind":"module","full_name":"DBX","name":"DBX"},"doc":"Handy `QueryBuilder` scope used into `Block`.","summary":"

Handy QueryBuilder scope used into Block.

","class_methods":[],"constructors":[{"id":"new(builder:QueryBuilder)-class-method","html_id":"new(builder:QueryBuilder)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"args_string":"(builder : QueryBuilder)","args_html":"(builder : QueryBuilder)","location":{"filename":"src/query_builder/scope.cr","line_number":13,"url":null},"def":{"name":"new","args":[{"name":"builder","doc":null,"default_value":"","external_name":"builder","restriction":"QueryBuilder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(builder)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"arg(value):String-instance-method","html_id":"arg(value):String-instance-method","name":"arg","doc":"Same as `QueryBuilder#add_arg`","summary":"

Same as QueryBuilder#add_arg

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : String","args_html":"(value) : String","location":{"filename":"src/query_builder/scope.cr","line_number":17,"url":null},"def":{"name":"arg","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.add_arg(value)"}},{"id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","html_id":"q(field:FieldType,io:IO::Memory):IO::Memory-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"args_string":"(field : FieldType, io : IO::Memory) : IO::Memory","args_html":"(field : FieldType, io : IO::Memory) : IO::Memory","location":{"filename":"src/query_builder/scope.cr","line_number":22,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"},{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":"IO::Memory"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"IO::Memory","visibility":"Public","body":"@builder.quote(field, io)"}},{"id":"q(field:FieldType):String-instance-method","html_id":"q(field:FieldType):String-instance-method","name":"q","doc":"Same as `QueryBuilder#quote`","summary":"

Same as QueryBuilder#quote

","abstract":false,"args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"args_string":"(field : FieldType) : String","args_html":"(field : FieldType) : String","location":{"filename":"src/query_builder/scope.cr","line_number":27,"url":null},"def":{"name":"q","args":[{"name":"field","doc":null,"default_value":"","external_name":"field","restriction":"FieldType"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@builder.quote(field)"}}],"macros":[],"types":[{"html_id":"dbx/DBX/QueryBuilderScope/FieldType","path":"DBX/QueryBuilderScope/FieldType.html","kind":"alias","full_name":"DBX::QueryBuilderScope::FieldType","name":"FieldType","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/query_builder/scope.cr","line_number":11,"url":null}],"repository_name":"dbx","program":false,"enum":false,"alias":true,"aliased":"(String | Symbol)","aliased_html":"String | Symbol","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"dbx/DBX/QueryBuilderScope","kind":"struct","full_name":"DBX::QueryBuilderScope","name":"QueryBuilderScope"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}]}}) \ No newline at end of file diff --git a/shard.yml b/shard.yml index 2f13fa2..f8026b6 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: dbx -version: 1.1.0 +version: 1.1.1 crystal: ">= 0.36.1" license: MIT