onyx-sql
Version, currently 0.2.139 versions
- 0.9.0latestAug 13, 2019
- 0.8.1not indexedMar 31, 2020
- 0.8.0not indexedMar 31, 2020
- 0.8.0-rc.1not indexedMar 31, 2020
- 0.7.3not indexedMar 31, 2020
- 0.7.2not indexedMar 31, 2020
- 0.7.1not indexedMar 31, 2020
- 0.7.0not indexedMar 31, 2020
- 0.6.2not indexedMar 31, 2020
- 0.6.1not indexedMar 31, 2020
- 0.6.0not indexedMar 31, 2020
- 0.5.0-beta.3not indexedMar 31, 2020
- 0.5.0-beta.2not indexedMar 31, 2020
- 0.5.0-beta.1not indexedMar 31, 2020
- 0.5.0-alpha.1not indexedMar 31, 2020
- 0.4.2not indexedMar 31, 2020
- 0.4.1not indexedMar 31, 2020
- 0.4.0not indexedMar 31, 2020
- 0.4.0-rc.3not indexedMar 31, 2020
- 0.4.0-rc.2not indexedMar 31, 2020
- 0.4.0-rc.1not indexedMar 31, 2020
- 0.4.0-pre.6not indexedMar 31, 2020
- 0.4.0-pre.5not indexedMar 31, 2020
- 0.4.0-pre.4not indexedMar 31, 2020
- 0.4.0-pre.3not indexedMar 31, 2020
- 0.4.0-pre.2not indexedMar 31, 2020
- 0.4.0-pre.1not indexedMar 31, 2020
- 0.3.4not indexedMar 31, 2020
- 0.3.3not indexedMar 31, 2020
- 0.3.2not indexedMar 31, 2020
- 0.3.1not indexedMar 31, 2020
- 0.3.0not indexedMar 31, 2020
- 0.2.3not indexedMar 31, 2020
- 0.2.2not indexedMar 31, 2020
- 0.2.1not indexedMar 31, 2020
- 0.2.0not indexedMar 31, 2020
- 0.1.2not indexedMar 31, 2020
- 0.1.1not indexedMar 31, 2020
- 0.1.0not indexedMar 31, 2020
github.com/onyxframework/sql
A delightful SQL ORM βΊοΈ
93 stars
2 dependents
License: MIT
Nothing has been indexed for 0.2.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
onyx-sql:
github: onyxframework/sql
version: ~> 0.2.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.2.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
<a href="https://onyxframework.org"><img width="100" height="100" src="https://onyxframework.org/img/logo.svg"></a>
# Onyx::SQL
[](https://crystal-lang.org/)
[](https://travis-ci.org/onyxframework/sql)
[](https://docs.onyxframework.org/sql)
[](https://api.onyxframework.org/sql)
[](https://github.com/onyxframework/sql/releases)
A deligtful SQL ORM.
## About π
Onyx::SQL is a deligthful database-agnostic SQL ORM for [Crystal language](https://crystal-lang.org/). It features a convenient schema definition DSL, type-safe SQL query builder, clean architecture with Repository and more!
## Installation π₯
Add these lines to your application's `shard.yml`:
```yaml
dependencies:
onyx:
github: onyxframework/onyx
version: ~> 0.6.0
onyx-sql:
github: onyxframework/sql
version: ~> 0.9.0
```
This shard follows [Semantic Versioning v2.0.0](http://semver.org/), so check [releases](https://github.com/onyxframework/rest/releases) and change the `version` accordingly.
> Note that until Crystal is officially released, this shard would be in beta state (`0.*.*`), with every **minor** release considered breaking. For example, `0.1.0` β `0.2.0` is breaking and `0.1.0` β `0.1.1` is not.
You'd also need to add a database dependency conforming to the [crystal-db](https://github.com/crystal-lang/crystal-db) interface. For example, [pg](https://github.com/will/crystal-pg):
```diff
dependencies:
onyx:
github: onyxframework/onyx
version: ~> 0.6.0
onyx-sql:
github: onyxframework/sql
version: ~> 0.9.0
+ pg:
+ github: will/crystal-pg
+ version: ~> 0.18.0
```
## Usage π»
For this PostgreSQL table:
```sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
```
Define the user schema:
```crystal
require "onyx/sql"
class User
include Onyx::SQL::Model
schema users do
pkey id : Int32
type name : String, not_null: true
type created_at : Time, not_null: true, default: true
end
end
```
Insert a new user instance:
```crystal
user = User.new(name: "John")
user = Onyx::SQL.query(user.insert.returning("*")).first
pp user # => #<User @id=1, @name="John", @created_at=#<Time ...>>
```
Query the user:
```crystal
user = Onyx::SQL.query(User.where(id: 1)).first?
```
With another PostgreSQL table:
```sql
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
author_id INT NOT NULL REFERENCES users(id),
content TEXT NOT NULL
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
```
Define the post schema:
```crystal
class Post
include Onyx::SQL::Model
schema posts do
pkey id : Int32
type author : User, not_null: true, key: "author_id"
type content : String, not_null: true
type created_at : Time, not_null: true, default: true
end
end
```
Add the posts reference to the user schema:
```diff
class User
include Onyx::SQL::Model
schema users do
pkey id : Int32
type name : String, not_null: true
type created_at : Time, not_null: true, default: true
+ type authored_posts : Array(Post), foreign_key: "author_id"
end
end
```
Create a new post:
```crystal
user = User.new(id: 1)
post = Post.new(author: user, content: "Hello, world!")
Onyx::SQL.exec(post.insert)
```
Query all the posts by a user with name "John":
```crystal
posts = Onyx::SQL.query(Post
.join(author: true) do |x|
x.select(:id, :name)
x.where(name: "John")
end
)
posts.first # => #<Post @id=1, @author=#<User @id=1 @name="John">, @content="Hello, world!">
```
## Documentation π
The documentation is available online at [docs.onyxframework.org/sql](https://docs.onyxframework.org/sql).
## Community πͺ
There are multiple places to talk about Onyx:
* [Gitter](https://gitter.im/onyxframework)
* [Twitter](https://twitter.com/onyxframework)
## Support π
This shard is maintained by me, [Vlad Faust](https://vladfaust.com), a passionate developer with years of programming and product experience. I love creating Open-Source and I want to be able to work full-time on Open-Source projects.
I will do my best to answer your questions in the free communication channels above, but if you want prioritized support, then please consider becoming my patron. Your issues will be labeled with your patronage status, and if you have a sponsor tier, then you and your team be able to communicate with me privately in [Twist](https://twist.com). There are other perks to consider, so please, don't hesistate to check my Patreon page:
<a href="https://www.patreon.com/vladfaust"><img height="50" src="https://onyxframework.org/img/patreon-button.svg"></a>
You could also help me a lot if you leave a star to this GitHub repository and spread the word about Crystal and Onyx! π£
## Contributing
1. Fork it ( https://github.com/onyxframework/sql/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'feat: some feature') using [Angular style commits](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit)
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [Vlad Faust](https://github.com/vladfaust) - creator and maintainer
## Licensing
This software is licensed under [MIT License](LICENSE).
[](https://opensource.org/licenses/MIT)
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.2.1- Tagged
- Mar 31, 2020
- Commit
016b72ad08b9- Indexed
- not yet
Dependents
Repository
github.com/onyxframework/sql
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 39