Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codec for resolve decoding error between mysql bit(1) and `s… #308

Merged
merged 1 commit into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ trait FinagleMysqlDecoders {
implicit val booleanDecoder: Decoder[Boolean] =
decoder[Boolean] {
case ByteValue(byte) => byte == (1: Byte)
case v: RawValue => v.bytes.head == (1: Byte)
}
implicit val byteDecoder: Decoder[Byte] =
decoder[Byte] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,31 @@ class FinagleMysqlEncodingSpec extends EncodingSpec {
}
}
}

"decode boolean types" - {
case class BooleanEncodingTestEntity(v1: Boolean, v2: Boolean)
val decodeBoolean = (entity: BooleanEncodingTestEntity) => {
val delete = quote(query[BooleanEncodingTestEntity].delete)
val insert = quote(query[BooleanEncodingTestEntity].insert)
val r = for {
_ <- testDB.run(delete)
_ <- testDB.run(insert)(List(entity))
result <- testDB.run(query[BooleanEncodingTestEntity])
} yield result
Await.result(r).head
}
"true" in {
val entity = BooleanEncodingTestEntity(true, true)
val r = decodeBoolean(entity)
r.v1 mustEqual true
r.v2 mustEqual true
}

"false" in {
val entity = BooleanEncodingTestEntity(false, false)
val r = decodeBoolean(entity)
r.v1 mustEqual false
r.v2 mustEqual false
}
}
}
5 changes: 5 additions & 0 deletions quill-sql/src/test/sql/mysql-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Create TABLE DateEncodingTestEntity(
v3 timestamp
);

Create TABLE BooleanEncodingTestEntity(
v1 BOOLEAN,
v2 BIT(1)
);

CREATE TABLE TestEntity(
s VARCHAR(255),
i INTEGER,
Expand Down
4 changes: 2 additions & 2 deletions quill-sql/src/test/sql/postgres-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE EncodingTestEntity(
v6 INTEGER,
v7 BIGINT,
v8 FLOAT,
v9 DOUBLE PRECISIOn,
v9 DOUBLE PRECISION,
v10 BYTEA,
v11 TIMESTAMP,
o1 VARCHAR(255),
Expand All @@ -43,7 +43,7 @@ CREATE TABLE EncodingTestEntity(
o6 INTEGER,
o7 BIGINT,
o8 FLOAT,
o9 DOUBLE PRECISIOn,
o9 DOUBLE PRECISION,
o10 BYTEA,
o11 TIMESTAMP
);
Expand Down