changed CHANGELOG.md
 
@@ -1,5 +1,17 @@
1
1
# Changelog
2
2
3
+ ## v0.4.2 (2020-09-11)
4
+
5
+ Enhancements:
6
+
7
+ * Encode `:zero_datetime` and `:zero_date`
8
+ * Consistently use `:supervisor.child_spec/0`
9
+ * Support Decimal v2.0
10
+
11
+ Bug fixes:
12
+
13
+ * Fix typespec for `MyXQL.stream/4`
14
+
3
15
## v0.4.1 (2020-05-27)
4
16
5
17
Bug fixes:
changed README.md
 
@@ -1,6 +1,6 @@
1
1
# MyXQL
2
2
3
- [![Build Status](https://travis-ci.org/elixir-ecto/myxql.svg?branch=master)](https://travis-ci.org/elixir-ecto/myxql)
3
+ [![CI](https://github.com/elixir-ecto/myxql/workflows/CI/badge.svg)](https://github.com/elixir-ecto/myxql/actions?query=workflow%3ACI)
4
4
5
5
MySQL driver for Elixir.
6
6
 
@@ -11,11 +11,9 @@ Documentation: <https://hexdocs.pm/myxql>
11
11
* Automatic decoding and encoding of Elixir values to and from MySQL text and binary protocols
12
12
* Supports transactions, prepared queries, streaming, pooling and more via [DBConnection](https://github.com/elixir-ecto/db_connection)
13
13
* Supports MySQL 5.5+, 8.0, and MariaDB 10.3
14
- * Supports `mysql_native_password`, `sha256_password` (\*), and `caching_sha2_password` (\*)
14
+ * Supports `mysql_native_password`, `sha256_password`, and `caching_sha2_password`
15
15
authentication plugins
16
16
17
- \* These authentication methods require either an SSL connection or the server must exchange its public key during handshake.
18
-
19
17
## Usage
20
18
21
19
Add `:myxql` to your dependencies:
 
@@ -23,7 +21,7 @@ Add `:myxql` to your dependencies:
23
21
```elixir
24
22
def deps() do
25
23
[
26
- {:myxql, "~> 0.3.0"}
24
+ {:myxql, "~> 0.4.0"}
27
25
]
28
26
end
29
27
```
 
@@ -91,31 +89,33 @@ NULL nil
91
89
bool 1 | 0
92
90
int 42
93
91
float 42.0
94
- decimal #Decimal<42.0> *
95
- date ~D[2013-10-12] **
96
- time ~T[00:37:14] ***
97
- datetime ~N[2013-10-12 00:37:14] ***, ****
98
- timestamp ~U[2013-10-12 00:37:14Z] ****
99
- json %{"foo" => "bar"} *****
92
+ decimal #Decimal<42.0> # (1)
93
+ date ~D[2013-10-12] # (2)
94
+ time ~T[00:37:14] # (3)
95
+ datetime ~N[2013-10-12 00:37:14] # (2), (4)
96
+ timestamp ~U[2013-10-12 00:37:14Z] # (2), (4)
97
+ json %{"foo" => "bar"} # (5)
100
98
char "é"
101
99
text "myxql"
102
100
binary <<1, 2, 3>>
103
101
bit <<1::size(1), 0::size(1)>>
104
- point, polygon, ... %Geo.Point{coordinates: {0.0, 1.0}}, ... ******
102
+ point, polygon, ... %Geo.Point{coordinates: {0.0, 1.0}}, ... # (6)
105
103
```
106
104
107
- \* See [Decimal](https://github.com/ericmj/decimal)
105
+ Notes:
108
106
109
- \*\* When using SQL mode that allows them, MySQL "zero" dates and datetimes are represented as `:zero_date` and `:zero_datetime` respectively.
107
+ 1. See [Decimal](https://github.com/ericmj/decimal)
110
108
111
- \*\*\* Negative or >= 24:00:00 values are not supported
109
+ 2. When using SQL mode that allows them, MySQL "zero" dates and datetimes are represented as `:zero_date` and `:zero_datetime` respectively.
112
110
113
- \*\*\*\* Datetime fields are represented as `NaiveDateTime`, however a UTC `DateTime` can be used for encoding as well
111
+ 3. Values that are negative or greater than `24:00:00` cannot be decoded
114
112
115
- \*\*\*\*\* MySQL added a native JSON type in version 5.7.8, if you're using earlier versions,
113
+ 4. Datetime fields are represented as `NaiveDateTime`, however a UTC `DateTime` can be used for encoding as well
114
+
115
+ 5. MySQL added a native JSON type in version 5.7.8, if you're using earlier versions,
116
116
remember to use TEXT column for your JSON field.
117
117
118
- \*\*\*\*\*\* See "Geometry support" section below
118
+ 6. See "Geometry support" section below
119
119
120
120
## JSON support
changed hex_metadata.config
 
@@ -1,7 +1,7 @@
1
1
{<<"app">>,<<"myxql">>}.
2
2
{<<"build_tools">>,[<<"mix">>]}.
3
3
{<<"description">>,<<"MySQL 5.5+ driver for Elixir">>}.
4
- {<<"elixir">>,<<"~> 1.4">>}.
4
+ {<<"elixir">>,<<"~> 1.6">>}.
5
5
{<<"files">>,
6
6
[<<"lib">>,<<"lib/myxql">>,<<"lib/myxql/client.ex">>,
7
7
<<"lib/myxql/protocol.ex">>,<<"lib/myxql/error.ex">>,
 
@@ -26,7 +26,7 @@
26
26
{<<"name">>,<<"decimal">>},
27
27
{<<"optional">>,false},
28
28
{<<"repository">>,<<"hexpm">>},
29
- {<<"requirement">>,<<"~> 1.6">>}],
29
+ {<<"requirement">>,<<"~> 1.6 or ~> 2.0">>}],
30
30
[{<<"app">>,<<"jason">>},
31
31
{<<"name">>,<<"jason">>},
32
32
{<<"optional">>,true},
 
@@ -37,4 +37,4 @@
37
37
{<<"optional">>,true},
38
38
{<<"repository">>,<<"hexpm">>},
39
39
{<<"requirement">>,<<"~> 3.3">>}]]}.
40
- {<<"version">>,<<"0.4.1">>}.
40
+ {<<"version">>,<<"0.4.2">>}.
changed lib/myxql.ex
 
@@ -27,6 +27,8 @@ defmodule MyXQL do
27
27
28
28
@type option() :: DBConnection.option()
29
29
30
+ @type stream_option() :: option() | {:max_rows, pos_integer()}
31
+
30
32
@doc """
31
33
Starts the connection process and connects to a MySQL server.
32
34
 
@@ -269,7 +271,7 @@ defmodule MyXQL do
269
271
270
272
## Options
271
273
272
- Options are passed to `DBConnection.prepare/4`, see it's documentation for
274
+ Options are passed to `DBConnection.prepare/3`, see it's documentation for
273
275
all available options.
274
276
275
277
## Examples
 
@@ -500,7 +502,7 @@ defmodule MyXQL do
500
502
501
503
And that would be the last result in the stream.
502
504
"""
503
- @spec stream(DBConnection.t(), iodata | MyXQL.Query.t(), list, [option()]) ::
505
+ @spec stream(DBConnection.t(), iodata | MyXQL.Query.t(), list, [stream_option()]) ::
504
506
DBConnection.PrepareStream.t()
505
507
def stream(conn, query, params \\ [], opts \\ [])
506
508
 
@@ -518,7 +520,7 @@ defmodule MyXQL do
518
520
@doc """
519
521
Returns a supervisor child specification for a DBConnection pool.
520
522
"""
521
- @spec child_spec([start_option()]) :: Supervisor.child_spec()
523
+ @spec child_spec([start_option()]) :: :supervisor.child_spec()
522
524
def child_spec(opts) do
523
525
ensure_deps_started!(opts)
524
526
DBConnection.child_spec(MyXQL.Connection, opts)
changed lib/myxql/protocol/values.ex
 
@@ -198,12 +198,28 @@ defmodule MyXQL.Protocol.Values do
198
198
{:mysql_type_date, <<4, year::uint2, month::uint1, day::uint1>>}
199
199
end
200
200
201
+ def encode_binary_value(:zero_date) do
202
+ {:mysql_type_date, <<4, 0::uint2, 0::uint1, 0::uint1>>}
203
+ end
204
+
201
205
def encode_binary_value(%Time{} = time), do: encode_binary_time(time)
202
206
203
207
def encode_binary_value(%NaiveDateTime{} = datetime), do: encode_binary_datetime(datetime)
204
208
205
209
def encode_binary_value(%DateTime{} = datetime), do: encode_binary_datetime(datetime)
206
210
211
+ def encode_binary_value(:zero_datetime) do
212
+ encode_binary_datetime(%NaiveDateTime{
213
+ year: 0,
214
+ month: 0,
215
+ day: 0,
216
+ hour: 0,
217
+ minute: 0,
218
+ second: 0,
219
+ microsecond: {0, 0}
220
+ })
221
+ end
222
+
207
223
def encode_binary_value(binary) when is_binary(binary) do
208
224
{:mysql_type_var_string, encode_string_lenenc(binary)}
209
225
end
changed mix.exs
 
@@ -1,14 +1,14 @@
1
1
defmodule MyXQL.MixProject do
2
2
use Mix.Project
3
3
4
- @version "0.4.1"
4
+ @version "0.4.2"
5
5
@source_url "https://github.com/elixir-ecto/myxql"
6
6
7
7
def project() do
8
8
[
9
9
app: :myxql,
10
10
version: @version,
11
- elixir: "~> 1.4",
11
+ elixir: "~> 1.6",
12
12
start_permanent: Mix.env() == :prod,
13
13
name: "MyXQL",
14
14
description: "MySQL 5.5+ driver for Elixir",
 
@@ -46,7 +46,7 @@ defmodule MyXQL.MixProject do
46
46
defp deps() do
47
47
[
48
48
{:db_connection, "~> 2.0", db_connection_opts()},
49
- {:decimal, "~> 1.6"},
49
+ {:decimal, "~> 1.6 or ~> 2.0"},
50
50
{:jason, "~> 1.0", optional: true},
51
51
{:geo, "~> 3.3", optional: true},
52
52
{:binpp, ">= 0.0.0", only: [:dev, :test]},