tren alternatives and similar shards
Based on the "Misc" category.
Alternatively, view tren alternatives based on common mentions on social networks and blogs.
-
sentry
Build/Runs your crystal application, watches files, and rebuilds/restarts app on file changes -
burocracia.cr
👔 Zero-dependency Crystal shard to validate, generate and format Brazilian burocracias (CPF, CNPJ, CEP) -
wikicr
Wiki in crystal, using Markdown and Git, inspired by dokuwiki. Last features to build are pretty hard, if you have some time to help... :) -
defined
This shard provides facilities for checking whether a constant exists at compile time, and for a variety of different conditional compilation options. Code can be conditionally compiled based on the existence of a constant, version number constraints, or whether an environment variable is set truthy or not.
CodeRabbit: AI Code Reviews for Developers
Do you think we are missing an alternative of tren or a related project?
README
[Tren Logo](logo.png)
Tren lets you use your SQL as a first class method in your Crystal code.
Installation
Add this to your application's shard.yml
:
dependencies:
tren:
github: sdogruyol/tren
Usage
Create a simple SQL file. The first line must be -- name: your_method_name(args)
.
-- name: get_users(name : String, surname : String)
SELECT * FROM users WHERE name = '{{ name }}' AND surname = '{{ surname }}'
Require Tren and load your SQL file. It's going to create a first class method to your SQL.
require "tren"
Tren.load("/path/to/your/file.sql")
# Or you can load multiple files at once:
Tren.load("./db/**/*.sql")
Overloading
-- name: get_users(name : String, surname : String)
SELECT * FROM users WHERE name = '{{ name }}' AND surname = '{{ surname }}'
-- name: get_users(name : String, age : Int32)
SELECT * FROM users WHERE name = '{{ name }}' AND age = {{ age }}
Meaningful Compiler Errors
Since Tren is creating native Crystal methods, you can see meaningful errors on compile process.
in ./your/file: no overload matches 'get_users' with types String, Bool
Overloads are:
- get_users(name : String, surname : String)
- get_users(name : String, age : Int32)
get_users("john", true)
Prevent SQL Injections
SQL statements are escaped by default. But you are able to make injectable (raw) parameters by writing !
to the parameter.
-- name: get_users(name : String, surname : String)
SELECT * FROM users WHERE name = '{{! name }}' AND surname = '{{! surname }}'
Composing SQLs
You can compose Tren methods easily to be DRY.
-- name: filter_user(name : String, surname : String)
WHERE name = '{{ name }}' AND surname = '{{ surname }}'
Let's reuse this now:
-- name: get_users(name : String, surname : String)
SELECT * FROM users {{! filter_user(name, surname) }}
Escape Character
For example PostgreSQL uses ''
for escaping string. To set your escape character for postgresql
.
Tren.escape_character = "\\'"
Contributing
- Fork it ( https://github.com/sdogruyol/tren/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
Built on a TREN from Ankara to Istanbul.