Clear ORM
Search…
Setup

Setup: As new project

Clear offers a CLI (Command Line Interface) which is still in Alpha. Documentation for building a new project with Clear + Kemal will be written once the feature is done. As of now, you can just follow the paragraph below.

Setup: In existing project

1
$ crystal init app <yourappname>
2
$ cd <yourappname>
Copied!

In `shard.yml`

Add your dependency in the dependencies list of your shard.yml
/shard.yml
1
dependencies:
2
clear:
3
github: anykeyh/clear
4
branch: master
Copied!
Then download the library:
terminal
1
$ shards install
Copied!

In your source code

Assuming your main entry point of your application is src/main.cr , you can require and initialize Clear:
src/main.cr
1
# append to your require list on top:
2
require "clear"
3
4
# initialize a pool of database connection:
5
Clear::SQL.init("postgres://[email protected]/my_database",
6
connection_pool_size: 5)
Copied!

Step by Step

  • require "clear" load the source code of Clear and provide everything needed to use the library.
  • Clear::SQL.init prepare a certain number of connection to your database. The URL is a convention used to connect to the database, and follow this schema:
1
postgres://USER[:PASSWORD]@HOST/DATABASE[?*OPTIONS]
Copied!
More information about the URL notation can be found here
  • connection_pool_size: 5 is optional but offers the possibility to concurrent fibers to run query at the same time. It's useful if you use an event-driven server, like Kemal.

Installation customization

You may want to install a smaller version of Clear by calling :
1
require "clear/core"
Copied!
This will add clear without the build-in CLI and without some extensions (jsonb, bcrypt etc...).
Last modified 1yr ago