-
Notifications
You must be signed in to change notification settings - Fork 89
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 to DBConnection 2.0 #235
Merged
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f9f3af6
Remove Docker dependent test
e0bcf00
Update decimal
wojtekmach e9c575c
Use database transaction status to prevent transaction errors
fishcakez dd2dc21
Use one text statement for all queries
fishcakez 0491f72
Support explicit cursor API
fishcakez 9f2350d
Remove reserved query name errors
fishcakez 869c0b7
Add max rows option to each cursor fetch
fishcakez c1c7475
Raise DBConnection.ConnectionError on connection error
fishcakez 02bc0fb
Update to DBConnection 2.0
e319241
Update to latest DBCOnnection
6abbee2
Update to latest DBConnection
6783f8f
Update docs
1f33f8e
Fix return types
31e896a
Update types
0483010
Update dbconnection reference
f9a48cc
Remove outdated pool config
8841917
Add Mariaex.prepare_execute
642d650
Update mariaex.ex
josevalim ec14055
Update DBConnection git ref
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -138,12 +138,11 @@ defmodule Mariaex do | |
def query(conn, statement, params, opts) do | ||
case Keyword.get(opts, :query_type) do | ||
:text -> | ||
query = %Query{type: :text, statement: statement, ref: make_ref(), | ||
num_params: 0} | ||
execute(conn, query, [], opts) | ||
query = %Query{type: :text, statement: statement, ref: make_ref(), num_params: 0} | ||
run_query(:execute, conn, query, [], opts) | ||
type when type in [:binary, nil] -> | ||
query = %Query{type: type, statement: statement} | ||
prepare_execute(conn, query, params, defaults(opts)) | ||
run_query(:prepare_execute, conn, query, params, defaults(opts)) | ||
end | ||
end | ||
|
||
|
@@ -237,14 +236,9 @@ defmodule Mariaex do | |
Mariaex.execute(conn, query, ["%my%"]) | ||
""" | ||
@spec execute(conn, Mariaex.Query.t, list, Keyword.t) :: | ||
{:ok, Mariaex.Result.t} | {:error, Mariaex.Error.t} | ||
{:ok, Mariaex.Query.t, Mariaex.Result.t} | {:error, Mariaex.Error.t} | ||
def execute(conn, %Query{} = query, params, opts \\ []) do | ||
case DBConnection.execute(conn, query, params, defaults(opts)) do | ||
{:error, %ArgumentError{} = err} -> | ||
raise err | ||
other -> | ||
other | ||
end | ||
DBConnection.execute(conn, query, params, defaults(opts)) | ||
end | ||
|
||
@doc """ | ||
|
@@ -253,12 +247,7 @@ defmodule Mariaex do | |
""" | ||
@spec execute!(conn, Mariaex.Query.t, list, Keyword.t) :: Mariaex.Result.t | ||
def execute!(conn, query, params, opts \\ []) do | ||
case execute(conn, query, params, opts) do | ||
{:ok, res} -> | ||
res | ||
{:error, err} -> | ||
raise err | ||
end | ||
DBConnection.execute!(conn, query, params, defaults(opts)) | ||
end | ||
|
||
@doc """ | ||
|
@@ -289,10 +278,8 @@ defmodule Mariaex do | |
case DBConnection.close(conn, query, defaults(opts)) do | ||
{:ok, _} -> | ||
:ok | ||
{:error, %ArgumentError{} = err} -> | ||
raise err | ||
other -> | ||
other | ||
{:error, err} -> | ||
err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this right, don't we want to return the error tuple? |
||
end | ||
end | ||
|
||
|
@@ -417,23 +404,21 @@ defmodule Mariaex do | |
|
||
## Helpers | ||
|
||
defp prepare_execute(conn, query, params, opts) do | ||
case DBConnection.prepare_execute(conn, query, params, defaults(opts)) do | ||
defp run_query(op, conn, query, params, opts) do | ||
case apply(DBConnection, op, [conn, query, params, defaults(opts)]) do | ||
{:ok, _, result} -> | ||
{:ok, result} | ||
{:error, %ArgumentError{} = err} -> | ||
raise err | ||
{:error, _} = error -> | ||
error | ||
end | ||
end | ||
|
||
defp prepare_binary(conn, query, opts) do | ||
case DBConnection.prepare(conn, query, defaults(opts)) do | ||
{:error, %ArgumentError{} = err} -> | ||
raise err | ||
other -> | ||
other | ||
{:ok, _} = ok -> | ||
ok | ||
{:error, err} -> | ||
err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
end | ||
end | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can now return other exceptions in the error case?