Crecto
Search…
Getting Started

Installation

Add the shard to your applications shard.yml
1
dependencies:
2
crecto:
3
github: Crecto/crecto
Copied!
Include a database adapter:
  • Postgres
Include crystal-pg in your project before Crecto.
1
require "pg"
2
require "crecto"
Copied!
  • Mysql
Include crystal-mysql in your project before Crecto.
1
require "mysql"
2
require "crecto"
Copied!
  • SQLite
Include crystal-sqlite3 in your project before Crecto.
1
require "sqlite3"
2
require "crecto"
Copied!

Example Usage

1
module MyRepo
2
extend Crecto::Repo
3
4
config do |conf|
5
conf.adapter = Crecto::Adapters::Postgres
6
conf.hostname = "localhost"
7
conf.database = "my_database"
8
end
9
end
10
11
class User < Crecto::Model
12
schema "users" do # table name
13
field :first_name, String
14
field :last_name, String
15
end
16
17
validate_required [:first_name, :last_name]
18
end
19
20
user = User.new
21
user.first_name = "fred"
22
user.last_name = "flinstone"
23
changeset = MyRepo.insert(user)
24
changeset.errors.any?
25
changeset.valid?
Copied!
Last modified 2yr ago
Copy link