Skip to content

Commit

Permalink
Crystal v0.30.0 changes (#354)
Browse files Browse the repository at this point in the history
* Upgrade to Crystal v0.30.0

* docker-compose now loads the .env automatically

* fix format

* crystal generates a warning

Crystal has a deprecation warning that causes the build to fail.
Disabling `--error-on-warnings` for now.

* update to latest releases
  • Loading branch information
drujensen authored Aug 7, 2019
1 parent 9a2d4fe commit a866c10
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 36 deletions.
16 changes: 8 additions & 8 deletions .env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export PG_DATABASE_URL=postgres://granite:password@localhost:5432/granite_db
export MYSQL_DATABASE_URL=mysql://granite:password@localhost:3306/granite_db
export SQLITE_DATABASE_URL=sqlite3:./granite.db
export CURRENT_ADAPTER=pg
export PG_VERSION=10.4
export MYSQL_VERSION=5.7
export SQLITE_VERSION=3110000
export SQLITE_VERSION_YEAR=2016
PG_DATABASE_URL=postgres://granite:password@localhost:5432/granite_db
MYSQL_DATABASE_URL=mysql://granite:password@localhost:3306/granite_db
SQLITE_DATABASE_URL=sqlite3:./granite.db
CURRENT_ADAPTER=pg
PG_VERSION=10.4
MYSQL_VERSION=5.7
SQLITE_VERSION=3110000
SQLITE_VERSION_YEAR=2016
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM crystallang/crystal:0.29.0
FROM crystallang/crystal:0.30.0

ARG sqlite_version=3110000
ARG sqlite_version_year=2016
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ The test suite depends on access to a PostgreSQL, MySQL, and SQLite database to
There is a self-contained testing environment provided via the `docker-compose.yml` file in this repository.
We are testing against multiple databases so you have to specify which docker-compose file you would like to use.
Replace "{database_type}" with "mysql" or "pg" or "sqlite". Before you can run the docker configuration you have to set the appropriate
env variables. To do so you can either load them yourself or load the .env file

```
$ source .env
```
env variables. To do so you can either load them yourself or modify the `.env` file that docker-compose loads by default.

You can find postgres versions at https://hub.docker.com/_/postgres/
You can find mysql versions at https://hub.docker.com/_/mysql/
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'
services:
spec:
build: .
command: 'bash -c "cd /app/user && bin/ameba && crystal tool format --check && crystal spec --warnings all --error-on-warnings"'
command: 'bash -c "cd /app/user && bin/ameba && crystal tool format --check && crystal spec --warnings all"'
working_dir: /app/user
environment:
PG_DATABASE_URL: 'postgres://postgres:@pg:5432/postgres'
Expand Down
8 changes: 4 additions & 4 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ license: MIT
dependencies:
db:
github: crystal-lang/crystal-db
version: ~> 0.5.1
version: ~> 0.6.0

development_dependencies:
mysql:
github: crystal-lang/crystal-mysql
version: ~> 0.7.0
version: ~> 0.8.0

sqlite3:
github: crystal-lang/crystal-sqlite3
version: ~> 0.12.0
version: ~> 0.13.0

pg:
github: will/crystal-pg
version: ~> 0.16.1
version: ~> 0.18.0

ameba:
github: veelenga/ameba
Expand Down
4 changes: 2 additions & 2 deletions spec/granite/converters/uuid_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe Granite::Converters::Uuid do
describe ".to_db" do
it "should convert a UUID enum into Bytes" do
uuid = UUID.random
Granite::Converters::Uuid(Bytes).to_db(uuid).should eq uuid.to_slice
Granite::Converters::Uuid(Bytes).to_db(uuid).should eq uuid.bytes.to_slice
end
end

Expand All @@ -34,7 +34,7 @@ describe Granite::Converters::Uuid do
uuid = UUID.new "cfe37f98-fdbf-43a3-b3d8-9c3288fb9ba6"

rs = FieldEmitter.new.tap do |e|
e._set_values([uuid.to_slice])
e._set_values([uuid.bytes.to_slice])
end

Granite::Converters::Uuid(Bytes).from_rs(rs).should eq uuid
Expand Down
6 changes: 3 additions & 3 deletions spec/granite/query/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ end

def builder
{% if env("CURRENT_ADAPTER").id == "pg" %}
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Pg
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Pg
{% elsif env("CURRENT_ADAPTER").id == "mysql" %}
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Mysql
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Mysql
{% else %}
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Sqlite
Granite::Query::Builder(Model).new Granite::Query::Builder::DbType::Sqlite
{% end %}
end

Expand Down
17 changes: 9 additions & 8 deletions spec/mocks/db_mock.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ class FakeStatement < DB::Statement
FieldEmitter.new
end

protected def perform_exec(args : Enumerable)
protected def perform_exec(args : Enumerable) : DB::ExecResult
DB::ExecResult.new 0_i64, 0_i64
end
end

class FakeContext
include DB::ConnectionContext

def uri
def uri : URI
URI.new ""
end

def prepared_statements?
def prepared_statements? : Bool
false
end

Expand All @@ -30,11 +30,11 @@ class FakeConnection < DB::Connection
@prepared_statements = false
end

def build_unprepared_statement(query : String)
def build_unprepared_statement(query : String) : FakeStatement
FakeStatement.new self
end

def build_prepared_statement(query : String)
def build_prepared_statement(query : String) : FakeStatement
FakeStatement.new self
end
end
Expand Down Expand Up @@ -65,9 +65,10 @@ class FieldEmitter < DB::ResultSet
end
end

def move_next
def move_next : Bool
@position += 1
@field_position = 0
@position < @values.size
end

def read
Expand All @@ -80,11 +81,11 @@ class FieldEmitter < DB::ResultSet
end
end

def column_count
def column_count : Int32
@values.size
end

def column_name(index : Int32)
def column_name(index : Int32) : String
"Column #{index}"
end
end
2 changes: 1 addition & 1 deletion src/adapter/mysql.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Granite::Adapter::Mysql < Granite::Adapter::Base
log statement, elapsed_time
end

def insert(table_name : String, fields, params, lastval)
def insert(table_name : String, fields, params, lastval) : Int64
statement = String.build do |stmt|
stmt << "INSERT INTO #{quote(table_name)} ("
stmt << fields.map { |name| "#{quote(name)}" }.join(", ")
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/pg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Granite::Adapter::Pg < Granite::Adapter::Base
log statement, elapsed_time
end

def insert(table_name : String, fields, params, lastval)
def insert(table_name : String, fields, params, lastval) : Int64
statement = String.build do |stmt|
stmt << "INSERT INTO #{quote(table_name)} ("
stmt << fields.map { |name| "#{quote(name)}" }.join(", ")
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/sqlite.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Granite::Adapter::Sqlite < Granite::Adapter::Base
log statement, elapsed_time
end

def insert(table_name : String, fields, params, lastval)
def insert(table_name : String, fields, params, lastval) : Int64
statement = String.build do |stmt|
stmt << "INSERT INTO #{quote(table_name)} ("
stmt << fields.map { |name| "#{quote(name)}" }.join(", ")
Expand Down
4 changes: 3 additions & 1 deletion src/granite/converters.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Granite::Converters
{% if T == String %}
value.to_s
{% elsif T == Bytes %}
value.to_slice.dup
# we need a heap allocated slice
v = value.bytes.each.to_a
Slice.new(v.to_unsafe, v.size)
{% else %}
{% raise "#{@type.name}#to_db does not support #{T} yet." %}
{% end %}
Expand Down

0 comments on commit a866c10

Please sign in to comment.