All Projects → onyxframework → Sql

onyxframework / Sql

Licence: mit
A delightful SQL ORM ☺️

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to Sql

Android Orma
An ORM for Android with type-safety and painless smart migrations
Stars: ✭ 442 (+396.63%)
Mutual labels:  sql, orm, query-builder
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-5.62%)
Mutual labels:  sql, orm, query-builder
Marlow
golang generator for type-safe sql api constructs
Stars: ✭ 83 (-6.74%)
Mutual labels:  sql, orm
Sqlz
SQL Query Builder for Go
Stars: ✭ 36 (-59.55%)
Mutual labels:  sql, query-builder
Reform
A better ORM for Go, based on non-empty interfaces and code generation.
Stars: ✭ 1,103 (+1139.33%)
Mutual labels:  sql, orm
Express Knex Objection
A simple API system on a pg database, using knex and objection to simplify connection and management
Stars: ✭ 20 (-77.53%)
Mutual labels:  sql, orm
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+964.04%)
Mutual labels:  sql, orm
Squid
🦑 Provides SQL tagged template strings and schema definition functions.
Stars: ✭ 57 (-35.96%)
Mutual labels:  sql, query-builder
Orm
PHP DataMapper, ORM
Stars: ✭ 827 (+829.21%)
Mutual labels:  orm, query-builder
Pqt
Postgres schema definition, sql/go, code generation package.
Stars: ✭ 65 (-26.97%)
Mutual labels:  sql, orm
Sqlite orm
❤️ SQLite ORM light header only library for modern C++
Stars: ✭ 1,121 (+1159.55%)
Mutual labels:  sql, orm
Examples Orms
Sample uses of CockroachDB with popular ORMs
Stars: ✭ 65 (-26.97%)
Mutual labels:  sql, orm
Ktorm
A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.
Stars: ✭ 843 (+847.19%)
Mutual labels:  sql, orm
Php Es Mapper
An elasticsearch simple mapping ORM for php
Stars: ✭ 25 (-71.91%)
Mutual labels:  orm, query-builder
Sequelize
Sequelize module for Nest framework (node.js) 🍈
Stars: ✭ 88 (-1.12%)
Mutual labels:  sql, orm
Reiner
萊納 - A MySQL wrapper which might be better than the ORMs and written in Golang
Stars: ✭ 19 (-78.65%)
Mutual labels:  sql, query-builder
Fluent
Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
Stars: ✭ 1,071 (+1103.37%)
Mutual labels:  sql, orm
Records
SQL for Humans™
Stars: ✭ 6,761 (+7496.63%)
Mutual labels:  sql, orm
Diesel
A safe, extensible ORM and Query Builder for Rust
Stars: ✭ 7,702 (+8553.93%)
Mutual labels:  orm, query-builder
Objectivesql
ObjectiveSQL is an ORM framework in Java based on ActiveRecord pattern, which encourages rapid development and clean, codes with the least and convention over configuration.
Stars: ✭ 1,109 (+1146.07%)
Mutual labels:  sql, orm

Onyx::SQL

Built with Crystal Travis CI build Docs API docs Latest release

A deligtful SQL ORM.

About 👋

Onyx::SQL is a deligthful database-agnostic SQL ORM for Crystal language. 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:

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, so check 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.00.2.0 is breaking and 0.1.00.1.1 is not.

You'd also need to add a database dependency conforming to the crystal-db interface. For example, pg:

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:

CREATE TABLE users (
  id          SERIAL      PRIMARY KEY,
  name        TEXT        NOT NULL
  created_at  TIMESTAMPTZ NOT NULL  DEFAULT now()
);

Define the user schema:

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:

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:

user = Onyx::SQL.query(User.where(id: 1)).first?

With another PostgreSQL table:

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:

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:

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:

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":

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.

Community 🍪

There are multiple places to talk about Onyx:

Support 🕊

This shard is maintained by me, Vlad Faust, 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. There are other perks to consider, so please, don't hesistate to check my Patreon page:

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
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Licensing

This software is licensed under MIT License.

Open Source Initiative

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].