Skip to content

Commit

Permalink
Upgrade everything and remove dependency on bs-json
Browse files Browse the repository at this point in the history
Still have bs-json as a development dependency, but it's
no longer a hard dependency.
  • Loading branch information
scull7 committed Jun 1, 2019
1 parent 409c606 commit 4f3b54d
Show file tree
Hide file tree
Showing 19 changed files with 6,712 additions and 431 deletions.
8 changes: 4 additions & 4 deletions __tests__/Test_mysql2_error.re
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("MySql2 Error Handling", () => {
test("Should parse out an empty error with defaults", () => {
/* Use raw JS here toe retrieve a garbage object */
let e = [%raw {| (function () { return { message: "IDKWTM" } })() |}];
let actual = MySql2_error.fromJsToExn(e);
let actual = MySql2.Exn.fromJs(e)->MySql2.Exn.toExn;

Expect.expect(() =>
raise(actual)
Expand All @@ -63,7 +63,7 @@ describe("MySql2 Error Handling", () => {
test("Should return a defaulted error", () => {
/* Use raw JS here toe retrieve a garbage object */
let e = [%raw {| (function () { return {} })()|}];
let actual = MySql2_error.fromJsToExn(e);
let actual = MySql2.Exn.fromJs(e)->MySql2.Exn.toExn;

Expect.expect(() =>
raise(actual)
Expand All @@ -74,7 +74,7 @@ describe("MySql2 Error Handling", () => {
test("should give appropriate message when only a sqlState is given", () => {
/* Use raw JS here toe retrieve a garbage object */
let e = [%raw {| (function () { return { sqlState: "test" } })()|}];
let actual = MySql2_error.fromJsToExn(e);
let actual = MySql2.Exn.fromJs(e)->MySql2.Exn.toExn;

Expect.expect(() =>
raise(actual)
Expand All @@ -87,7 +87,7 @@ describe("MySql2 Error Handling", () => {
test("should give appropriate message when only a sqlMessage is given", () => {
/* Use raw JS here toe retrieve a garbage object */
let e = [%raw {| (function () { return { sqlMessage: "test" } })()|}];
let actual = MySql2_error.fromJsToExn(e);
let actual = MySql2.Exn.fromJs(e)->MySql2.Exn.toExn;

Expect.expect(() =>
raise(actual)
Expand Down
12 changes: 6 additions & 6 deletions __tests__/Test_mysql2_id.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ open Jest;
describe("MySql2_id", () => {
describe("toJson", () =>
test("it should convert an id to a JSON string", () =>
MySql2_id.fromJson(42.0 |. Js.Json.number)
|. MySql2_id.toJson
|. Js.Json.decodeString
|. Belt.Option.getExn
MySql2.ID.fromJson(42.0->Js.Json.number)
->MySql2.ID.toJson
->Js.Json.decodeString
->Belt.Option.getExn
|> Expect.expect
|> Expect.toBe("42")
)
);

describe("fromJson", () => {
test("should fail when given a JSON boolean", () => {
let fn = () => Js.Json.boolean(true) |. MySql2_id.fromJson;
let fn = () => Js.Json.boolean(true)->MySql2.ID.fromJson;

Expect.expect(fn)
|> Expect.toThrowMessage("unexpected_identifier_value");
});

test("should fail when given a JSON array", () => {
let fn = () => Js.Json.array([||]) |. MySql2_id.fromJson;
let fn = () => Js.Json.array([||])->MySql2.ID.fromJson;

Expect.expect(fn)
|> Expect.toThrowMessage("unexpected_identifier_value");
Expand Down
58 changes: 28 additions & 30 deletions __tests__/Test_mysql2_response.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ open Jest;
describe("MySql2_response", () =>
describe("Select", () => {
let test_meta =
Json.Encode.(
object_([
("catalog", "catalog" |. string),
("schema", "schema" |. string),
("name", "name" |. string),
("orgName", "orgName" |. string),
("table", "table" |. string),
("orgTable", "orgTable" |. string),
("characterSet", 1 |. int),
("columnLength", 2 |. int),
("columnType", 3 |. int),
("flags", 4 |. int),
("decimals", 5 |. int),
])
MySql2.Meta.t(
~catalog="catalog",
~schema="schema",
~name="name",
~orgName="orgName",
~table="table",
~orgTable="orgTable",
~characterSet=1,
~columnLength=2,
~columnType=3,
~flags=4,
~decimals=5,
);

describe("concat", () =>
test("should combine the rows of two result sets", () => {
let rows1 = [|Js.Json.string("foo"), Js.Json.string("bar")|];
let rows2 = [|Js.Json.string("boo"), Js.Json.string("baz")|];

let t1 = MySql2_response.Select.make(rows1, [|test_meta|]);
let t2 = MySql2_response.Select.make(rows2, [|test_meta|]);
let t1 = MySql2.Select.make(~rows=rows1, ~meta=[|test_meta|]);
let t2 = MySql2.Select.make(~rows=rows2, ~meta=[|test_meta|]);

MySql2_response.Select.concat(t1, t2)
|. MySql2_response.Select.flatMap(x =>
x |. Js.Json.decodeString |. Belt.Option.getExn
)
|. Expect.expect
MySql2.Select.concat(t1, t2)
->(
MySql2.Select.flatMap(x =>
x->Js.Json.decodeString->Belt.Option.getExn
)
)
->Expect.expect
|> Expect.toEqual([|"foo", "bar", "boo", "baz"|]);
})
);

describe("count", () =>
test("count should return 0 when rows is empty", () =>
MySql2_response.Select.make([||], [|test_meta|])
|. MySql2_response.Select.count
|. Expect.expect
MySql2.Select.make(~rows=[||], ~meta=[|test_meta|])
->MySql2.Select.count
->Expect.expect
|> Expect.toBe(0)
)
);
Expand All @@ -49,12 +49,10 @@ describe("MySql2_response", () =>
test("rows should return the current set of rows", () => {
let rows = [|Js.Json.string("foo"), Js.Json.string("bar")|];

MySql2_response.Select.make(rows, [|test_meta|])
|. MySql2_response.Select.rows
|. Belt.Array.map(x =>
x |. Js.Json.decodeString |. Belt.Option.getExn
)
|. Expect.expect
MySql2.Select.make(~rows, ~meta=[|test_meta|])
->MySql2.Select.rows
->(Belt.Array.map(x => x->Js.Json.decodeString->Belt.Option.getExn))
->Expect.expect
|> Expect.toEqual([|"foo", "bar"|]);
})
);
Expand Down
32 changes: 0 additions & 32 deletions __tests__/parse_response.re

This file was deleted.

27 changes: 12 additions & 15 deletions __tests__/query.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Jest;

[@bs.val] [@bs.scope "Number"]
external max_safe_integer : int = "MAX_SAFE_INTEGER";
external max_safe_integer: int = "MAX_SAFE_INTEGER";

let connect = () =>
MySql2.Connection.connect(~host="127.0.0.1", ~port=3306, ~user="root", ());
Expand Down Expand Up @@ -41,8 +41,7 @@ describe("Raw SQL Query Test", () => {
"SHOW DATABASES",
None,
onSelect(finish, (select, next) =>
select
|. MySql2.Select.flatMap(Json.Decode.dict(Json.Decode.string))
select->(MySql2.Select.flatMap(Json.Decode.dict(Json.Decode.string)))
|> Js.Array.map(x => Js.Dict.unsafeGet(x, "Database"))
|> Expect.expect
|> Expect.toContain("test")
Expand Down Expand Up @@ -88,8 +87,8 @@ describe("Raw SQL Query Test Sequence", () => {
onMutation(finish, (mutation, next) =>
(
MySql2.Mutation.insertId(mutation)
|. Belt.Option.getExn
|. MySql2.Id.toString,
->Belt.Option.getExn
->MySql2.Id.toString,
MySql2.Mutation.affectedRows(mutation),
)
|> Expect.expect
Expand Down Expand Up @@ -123,8 +122,7 @@ describe("Raw SQL Query Test Sequence", () => {
sql,
None,
onSelect(finish, (select, next) =>
select
|. MySql2.Select.flatMap(decoder)
select->(MySql2.Select.flatMap(decoder))
|> Expect.expect
|> Expect.toHaveLength(0)
|> next
Expand All @@ -148,8 +146,7 @@ describe("Raw SQL Query Test Sequence", () => {
sql,
None,
onSelect(finish, (select, next) =>
select
|. MySql2.Select.flatMap(decoder)
select->(MySql2.Select.flatMap(decoder))
|> first_row
|> Expect.expect
|> Expect.toBeSupersetOf([|true, true|])
Expand All @@ -170,10 +167,10 @@ describe("Raw SQL Query Test Sequence", () => {
None,
onMutation(finish, (mutation, next) =>
MySql2.Mutation.insertId(mutation)
|. Belt.Option.getExn
|. MySql2.Id.toString
->Belt.Option.getExn
->MySql2.Id.toString
|> Expect.expect
|> Expect.toBe(max_safe_integer |. string_of_int)
|> Expect.toBe(max_safe_integer->string_of_int)
|> next
),
);
Expand All @@ -191,9 +188,9 @@ describe("Raw SQL Query Test Sequence", () => {
None,
onMutation(finish, (mutation, next) =>
mutation
|. MySql2.Mutation.insertId
|. Belt.Option.getExn
|. MySql2.Id.toString
->MySql2.Mutation.insertId
->Belt.Option.getExn
->MySql2.Id.toString
|> Expect.expect
|> Expect.toBe("9007199254740993")
|> next
Expand Down
4 changes: 2 additions & 2 deletions bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"type": "dev"
}
],
"bs-dev-dependencies": [ "@glennsl/bs-jest" ],
"bs-dependencies": [ "@glennsl/bs-json" ],
"bs-dev-dependencies": [ "@glennsl/bs-jest", "@glennsl/bs-json" ],
"bs-dependencies": [],
"bsc-flags": [ "-bs-super-errors" ],
"refmt": 3
}
Loading

0 comments on commit 4f3b54d

Please sign in to comment.