All Projects → fazibear → Defql

fazibear / Defql

Licence: mit
Create elixir functions with SQL as a body.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Defql

Lol dba
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Stars: ✭ 1,363 (+1263%)
Mutual labels:  sql, database
Node Mysql Utilities
Query builder for node-mysql with introspection, etc.
Stars: ✭ 98 (-2%)
Mutual labels:  sql, database
Deveeldb
DeveelDB is a complete SQL database system, primarly developed for .NET/Mono frameworks
Stars: ✭ 80 (-20%)
Mutual labels:  sql, database
Laravel Log To Db
Custom Laravel and Lumen 5.6+ Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel/Monolog native logging functionality.
Stars: ✭ 76 (-24%)
Mutual labels:  sql, database
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1167%)
Mutual labels:  sql, database
Suricatta
High level sql toolkit for clojure (backed by jooq library)
Stars: ✭ 77 (-23%)
Mutual labels:  sql, database
Cs Books
超过1000本的计算机经典书籍、个人笔记资料以及本人在各平台发表文章中所涉及的资源等。书籍资源包括C/C++、Java、Python、Go语言、数据结构与算法、操作系统、后端架构、计算机系统知识、数据库、计算机网络、设计模式、前端、汇编以及校招社招各种面经~
Stars: ✭ 1,215 (+1115%)
Mutual labels:  sql, database
Awesome Business Intelligence
Actively curated list of awesome BI tools. PRs welcome!
Stars: ✭ 1,157 (+1057%)
Mutual labels:  sql, database
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+1164%)
Mutual labels:  sql, database
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-16%)
Mutual labels:  sql, database
Locopy
locopy: Loading/Unloading to Redshift and Snowflake using Python.
Stars: ✭ 73 (-27%)
Mutual labels:  sql, database
Toydb
Distributed SQL database in Rust, written as a learning project
Stars: ✭ 1,329 (+1229%)
Mutual labels:  sql, database
Ebean
Ebean ORM
Stars: ✭ 1,172 (+1072%)
Mutual labels:  sql, database
Nodejs Spanner
Node.js client for Google Cloud Spanner: the world’s first fully managed relational database service to offer both strong consistency and horizontal scalability.
Stars: ✭ 80 (-20%)
Mutual labels:  sql, database
Scan
Scan database/sql rows directly to structs, slices, and primitive types
Stars: ✭ 69 (-31%)
Mutual labels:  sql, database
Clickhouse Go
Golang driver for ClickHouse
Stars: ✭ 1,234 (+1134%)
Mutual labels:  sql, database
Dbx
A neat codegen-based database wrapper written in Go
Stars: ✭ 68 (-32%)
Mutual labels:  sql, database
Directus Docker
Directus 6 Docker — Legacy Container [EOL]
Stars: ✭ 68 (-32%)
Mutual labels:  sql, database
Snowflake Jdbc
Snowflake JDBC Driver
Stars: ✭ 83 (-17%)
Mutual labels:  sql, database
Qtl
A friendly and lightweight C++ database library for MySQL, PostgreSQL, SQLite and ODBC.
Stars: ✭ 92 (-8%)
Mutual labels:  sql, database

Defql Package Version Code Climate Build Status

Create elixir functions with SQL as a body.

Installation

If available in Hex, the package can be installed by adding defql to your list of dependencies in mix.exs:

defp deps do
  [
    {:defql, "~> 0.1.1"},
    {:postgrex, ">= 0.13.0"}, # optional
  ]
end

Configuration

It requires adapter key, and adapter specific options.

Use with ecto:

config :defql, connection: [
  adapter: Defql.Adapter.Ecto.Postgres,
  repo: YourApp.Repo
]

Use standalone connection:

config :defql, connection: [
  adapter: Defql.Adapter.Postgres,
  hostname: "localhost",
  username: "username",
  password: "password",
  database: "my_db",
  pool: DBConnection.Poolboy,
  pool_size: 1
]

Usage

We can define module to have access to our database:

defmodule UserQuery do
  use Defql

  defselect get(conds), table: :users, columns: [:name, :email]
  definsert add(params), table: :users
  defupdate update(params, conds), table: :users
  defdelete delete(conds), table: :users

  defquery get_by_name(name, limit) do
    "SELECT * FROM users WHERE name = $name LIMIT $limit"
  end
end

Right now we have easy access to users in database:

UserQuery.get(id: "3") # => {:ok, [%{...}]}
UserQuery.add(name: "Smbdy") # => {:ok, [%{...}]}
UserQuery.update([name: "Other"],[id: "2"]) # => {:ok, [%{...}]}
UserQuery.delete(id: "2") # => {:ok, [%{...}]}

UserQuery.get_by_name("Ela", 4) # => {:ok, [%{...}, %{...}]}

We can also define common table for the whole module.

defmodule UserQuery do
  use Defql, table: :users

  defselect get(conds), columns: [:name, :email]
  definsert add(params)
  defupdate update(params, conds)
  defdelete delete(conds)
end

%{...} It's a hash with user properties straight from database.

Supported condition statements:

  • user_id: [1,2,3,4]
  • user_id: {:in, [1,2,3,4,5]}
  • name: {:like, "%john%"}
  • name: {:ilike, "%john"}

TODO

  • [ ] MySQL support
  • [ ] Cleanup ECTO adapter
  • [ ] Support database errors
  • [ ] Transactions

Thank you!

Become Patreon

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].