-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Release of 0.6; See CHANGELOG.md for all the changes
- Loading branch information
Showing
82 changed files
with
1,314 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: crystal | ||
script: | ||
- crystal spec | ||
- crystal spec -Dquiet | ||
- bin/ameba | ||
- crystal docs | ||
services: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CRYSTAL_BIN ?= $(shell which crystal) | ||
|
||
test: | ||
$(CRYSTAL_BIN) spec -Dquiet |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
# Migration CLI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# Bulk update | ||
## Bulk update | ||
|
||
Any simple query can be transformed to `update` query. The new update query will use the `where` clause as parameter | ||
for the update. | ||
|
||
```ruby | ||
User.query.where(name =~ /[A-Z]/ ). | ||
to_update.set(name: Clear::SQL.unsafe("LOWERCASE(name)")).execute | ||
``` | ||
|
||
## Bulk delete | ||
|
||
Same apply for DELETE query. | ||
|
||
```ruby | ||
User.query.where(name !~ /[A-Z]/ ). | ||
to_delete.execute | ||
``` | ||
|
||
{% hint style="warning" %} | ||
Beware: Bulk update and delete do not trigger any model lifecycle hook. Proceed with care. | ||
{% endhint %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,80 @@ | ||
# Converters | ||
|
||
Any type from PostgreSQL can be converted using converter objects. | ||
By default, Clear converts already the main type of PostgreSQL. | ||
|
||
However, custom type may not be supported yet. Clear offers you the possibility to add a custom converter. | ||
|
||
## Declare a new converter | ||
|
||
The example below with a converter for a `Color` structure shoudl be straight-forward: | ||
|
||
```ruby | ||
require "./base" | ||
|
||
struct MyApp::Color | ||
property r : UInt8 = 0 | ||
property g : UInt8 = 0 | ||
property b : UInt8 = 0 | ||
property a : UInt8 = 0 | ||
|
||
def to_s | ||
# ... | ||
end | ||
|
||
def self.from_string(x : String) | ||
# ... | ||
end | ||
|
||
def self.from_slice(x : Slice(UInt8)) | ||
# ... | ||
end | ||
end | ||
|
||
class MyApp::ColorConverter | ||
def self.to_column(x) : MyApp::Color? | ||
case x | ||
when Nil | ||
nil | ||
when Slice(UInt8) | ||
MyApp::Color.from_slice(x) | ||
when String | ||
MyApp::Color.from_string(x) | ||
else | ||
raise "Cannot convert from #{x.class} to MyApp::Color" | ||
end | ||
end | ||
|
||
def self.to_db(x : MyApp::Color?) | ||
x.to_s #< css style output, e.g. #12345400 | ||
end | ||
end | ||
|
||
Clear::Model::Converter.add_converter("MyApp::Color", MyApp::ColorConverter) | ||
``` | ||
|
||
Then you can use your mapped type in your model: | ||
|
||
```ruby | ||
class MyApp::MyModel | ||
include Clear::Model | ||
#... | ||
column color : Color #< Automatically get the converter | ||
end | ||
``` | ||
|
||
## `converter` option | ||
|
||
Optionally, you may want to use a converter which is not related to the type itself. To do so, you can pass the | ||
converter name as optional argument in the `column` declaration: | ||
|
||
```ruby | ||
class MyApp::MyModel | ||
include Clear::Model | ||
#... | ||
column s : String, converter: "my_custom_converter" | ||
end | ||
``` | ||
|
||
By convention, converters which map struct and class directly are named using CamelCase, while converters which are not | ||
automatic should be named using the underscore notation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: clear | ||
version: 0.5 | ||
version: 0.6 | ||
|
||
authors: | ||
- Yacine Petitprez <[email protected]> | ||
|
@@ -27,8 +27,8 @@ development_dependencies: | |
# github: anykeyh/crystal-coverage | ||
ameba: | ||
github: veelenga/ameba | ||
version: "~> 0.9" | ||
branch: master | ||
|
||
crystal: 0.27.0 | ||
crystal: 0.27.2 | ||
|
||
license: MIT |
Oops, something went wrong.