https://github.com/zweifisch/eno
Lightweight SQL toolkit for Elixir
https://github.com/zweifisch/eno
Last synced: 9 months ago
JSON representation
Lightweight SQL toolkit for Elixir
- Host: GitHub
- URL: https://github.com/zweifisch/eno
- Owner: zweifisch
- License: mit
- Created: 2016-04-30T11:14:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-07T06:06:02.000Z (about 10 years ago)
- Last Synced: 2024-11-11T02:09:27.182Z (over 1 year ago)
- Language: Elixir
- Homepage:
- Size: 17.6 KB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Eno
[![Build Status][travis-image]][travis-url]
Lightweight SQL toolkit for elixir inspired by [yesql](https://github.com/krisajenkins/yesql) and [ragtime](https://github.com/weavejester/ragtime).
For the moment only PostgreSQL is supported, and you need to add [postgrex](http://github.com/ericmj/postgrex) as a dependency.
## Installation
It's [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add eno to your list of dependencies in `mix.exs`:
def deps do
[{:eno, "~> 0.0.1"}]
end
## Usage
lib/yourapp/repo.ex
defmodule YourApp.Repo do
use Eno
end
lib/yourapp/repo.sql
-- name: user_list
select * from users offset :offset limit :limit;
-- name: user_get
select * from users where user_id = :id;
lib/yourapp.ex
children = [
worker(YourApp.Repo, []),
]
config/config.ex
config :eno, YourApp.Repo,
adapter: Eno.Adapters.Postgres,
hostname: "localhost",
username: "user",
password: "pass",
database: "db"
finally
iex> YourApp.Repo.user_list offset: 0, limit: 10
iex> YourApp.Repo.user_get 1
## Migration
$ mix eno.gen.migration init_users
priv/migrations/repo/20160507022535_init_users.up.sql
create table users (id SERIAL PRIMARY KEY, name varchar(255) NOT NULL UNIQUE);
priv/migrations/repo/20160507022535_init_users.down.sql
drop table users;
config/config.ex
config :yourapp,
eno_repos: [YourApp.Repo]
up
$ mix eno.migrate [-r YourApp.Repo]
down
$ mix eno.rollback [-r YourApp.Repo]
## Status
Not ready for production use yet. The API is subject to change.
[travis-image]: https://img.shields.io/travis/zweifisch/eno.svg?style=flat
[travis-url]: https://travis-ci.org/zweifisch/eno