Skip to content

Commit 6f548a1

Browse files
authored
Merge branch 'master' into master
2 parents b1991bc + 25ffb8a commit 6f548a1

19 files changed

+532
-203
lines changed

.credo.exs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs: [
11+
%{
12+
#
13+
# Run any exec using `mix credo -C <name>`. If no exec name is given
14+
# "default" is used.
15+
#
16+
name: "default",
17+
#
18+
# These are the files included in the analysis:
19+
files: %{
20+
#
21+
# You can give explicit globs or simply directories.
22+
# In the latter case `**/*.{ex,exs}` will be used.
23+
#
24+
included: ["lib/", "src/", "web/", "apps/"],
25+
excluded: [~r"/_build/", ~r"/deps/"]
26+
},
27+
#
28+
# If you create your own checks, you must specify the source files for
29+
# them here, so they can be loaded by Credo before running the analysis.
30+
#
31+
requires: [],
32+
#
33+
# If you want to enforce a style guide and need a more traditional linting
34+
# experience, you can change `strict` to `true` below:
35+
#
36+
strict: true,
37+
#
38+
# If you want to use uncolored output by default, you can change `color`
39+
# to `false` below:
40+
#
41+
color: true,
42+
#
43+
# You can customize the parameters of any check by adding a second element
44+
# to the tuple.
45+
#
46+
# To disable a check put `false` as second element:
47+
#
48+
# {Credo.Check.Design.DuplicatedCode, false}
49+
#
50+
checks: [
51+
{Credo.Check.Consistency.ExceptionNames},
52+
{Credo.Check.Consistency.LineEndings},
53+
{Credo.Check.Consistency.ParameterPatternMatching},
54+
{Credo.Check.Consistency.SpaceAroundOperators},
55+
{Credo.Check.Consistency.SpaceInParentheses},
56+
{Credo.Check.Consistency.TabsOrSpaces},
57+
58+
# You can customize the priority of any check
59+
# Priority values are: `low, normal, high, higher`
60+
#
61+
{Credo.Check.Design.AliasUsage, priority: :low},
62+
63+
# For some checks, you can also set other parameters
64+
#
65+
# If you don't want the `setup` and `test` macro calls in ExUnit tests
66+
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
67+
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
68+
#
69+
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
70+
71+
# You can also customize the exit_status of each check.
72+
# If you don't want TODO comments to cause `mix credo` to fail, just
73+
# set this value to 0 (zero).
74+
#
75+
{Credo.Check.Design.TagTODO, exit_status: 2},
76+
{Credo.Check.Design.TagFIXME},
77+
78+
{Credo.Check.Readability.FunctionNames},
79+
{Credo.Check.Readability.LargeNumbers},
80+
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 80},
81+
{Credo.Check.Readability.ModuleAttributeNames},
82+
{Credo.Check.Readability.ModuleDoc},
83+
{Credo.Check.Readability.ModuleNames},
84+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
85+
{Credo.Check.Readability.ParenthesesInCondition},
86+
{Credo.Check.Readability.PredicateFunctionNames},
87+
{Credo.Check.Readability.PreferImplicitTry},
88+
{Credo.Check.Readability.RedundantBlankLines},
89+
{Credo.Check.Readability.StringSigils},
90+
{Credo.Check.Readability.TrailingBlankLine},
91+
{Credo.Check.Readability.TrailingWhiteSpace},
92+
{Credo.Check.Readability.VariableNames},
93+
{Credo.Check.Readability.Semicolons},
94+
{Credo.Check.Readability.SpaceAfterCommas},
95+
96+
{Credo.Check.Refactor.DoubleBooleanNegation},
97+
{Credo.Check.Refactor.CondStatements},
98+
{Credo.Check.Refactor.CyclomaticComplexity},
99+
{Credo.Check.Refactor.FunctionArity},
100+
{Credo.Check.Refactor.LongQuoteBlocks},
101+
{Credo.Check.Refactor.MatchInCondition},
102+
{Credo.Check.Refactor.NegatedConditionsInUnless},
103+
{Credo.Check.Refactor.NegatedConditionsWithElse},
104+
{Credo.Check.Refactor.Nesting},
105+
{Credo.Check.Refactor.PipeChainStart},
106+
{Credo.Check.Refactor.UnlessWithElse},
107+
108+
{Credo.Check.Warning.BoolOperationOnSameValues},
109+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
110+
{Credo.Check.Warning.IExPry},
111+
{Credo.Check.Warning.IoInspect},
112+
{Credo.Check.Warning.LazyLogging},
113+
{Credo.Check.Warning.OperationOnSameValues},
114+
{Credo.Check.Warning.OperationWithConstantResult},
115+
{Credo.Check.Warning.UnusedEnumOperation},
116+
{Credo.Check.Warning.UnusedFileOperation},
117+
{Credo.Check.Warning.UnusedKeywordOperation},
118+
{Credo.Check.Warning.UnusedListOperation},
119+
{Credo.Check.Warning.UnusedPathOperation},
120+
{Credo.Check.Warning.UnusedRegexOperation},
121+
{Credo.Check.Warning.UnusedStringOperation},
122+
{Credo.Check.Warning.UnusedTupleOperation},
123+
{Credo.Check.Warning.RaiseInsideRescue},
124+
125+
# Controversial and experimental checks (opt-in, just remove `, false`)
126+
#
127+
{Credo.Check.Refactor.ABCSize, false},
128+
{Credo.Check.Refactor.AppendSingleItem, false},
129+
{Credo.Check.Refactor.VariableRebinding, false},
130+
{Credo.Check.Warning.MapGetUnsafePass, false},
131+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
132+
133+
# Deprecated checks (these will be deleted after a grace period)
134+
#
135+
{Credo.Check.Readability.Specs, false},
136+
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
137+
{Credo.Check.Warning.NameRedeclarationByCase, false},
138+
{Credo.Check.Warning.NameRedeclarationByDef, false},
139+
{Credo.Check.Warning.NameRedeclarationByFn, false},
140+
141+
# Custom checks can be created using `mix credo.gen.check`.
142+
#
143+
]
144+
}
145+
]
146+
}

.formatter.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
inputs: [
3+
"mix.exs",
4+
"{config,lib,test}/**/*.{ex,exs}"
5+
],
6+
line_length: 80
7+
]

README.md

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,119 @@
11
# Tds
22

3+
[![Hex.pm](https://img.shields.io/hexpm/v/tds.svg)](https://hex.pm/packages/tds) [![Build status](https://ci.appveyor.com/api/projects/status/aibnqbukppa3kcpt?svg=true)](https://ci.appveyor.com/project/mjaric/tds)
4+
35
MSSQL / TDS Database driver for Elixir.
46

5-
This is an alpha version that currently supports Ecto 2.0. It has implemented the [db_connection](https://github.com/elixir-ecto/db_connection) behaviour, and added support for transactions and prepared queries.
6-
Please check out the issues for a more complete overview. This branch should not yet be considered stable or used in production.
7+
Supports Ecto 2.0. It (mostly) implements the [db_connection](https://github.com/elixir-ecto/db_connection) behaviour and has support for transactions and prepared queries.
8+
9+
Please check out the issues for a more complete overview. This branch should not be considered stable or ready for production yet.
710

811
## Usage
912

1013
Add Tds as a dependency in your `mix.exs` file.
1114

1215
```elixir
1316
def deps do
14-
[{:tds, "~> 1.0.4"} ]
17+
[{:tds, "~> 1.0"} ]
1518
end
1619
```
1720

18-
After you are done, run `mix deps.get` in your shell to fetch and compile Tds. Start an interactive Elixir shell with `iex -S mix`.
21+
When you are done, run `mix deps.get` in your shell to fetch and compile Tds. Start an interactive Elixir shell with `iex -S mix`.
1922

2023
```iex
2124
iex> {:ok, pid} = Tds.start_link([hostname: "localhost", username: "test_user", password: "test_password", database: "test_db", port: 4000])
2225
{:ok, #PID<0.69.0>}
26+
2327
iex> Tds.query!(pid, "SELECT 'Some Awesome Text' AS MyColumn", [])
2428
%Tds.Result{columns: ["MyColumn"], rows: [{"Some Awesome Text"}], num_rows: 1}}
25-
iex> Tds.query!(pid, "INSERT INTO MyTable (MyColumn) VALUES (@my_value)", [%Tds.Parameter{name: "@my_value", value: "My Actual Value"}])
29+
30+
iex> Tds.query!(pid, "INSERT INTO MyTable (MyColumn) VALUES (@my_value)",
31+
...> [%Tds.Parameter{name: "@my_value", value: "My Actual Value"}])
2632
%Tds.Result{columns: nil, rows: nil, num_rows: 1}}
2733
```
2834

2935
## Features
3036

31-
* Automatic decoding and encoding of Elixir values to and from MSSQL's binary format
32-
* Supports TDS Version 7.3, 7.4
37+
* Automatic decoding and encoding of Elixir values to and from MSSQL's binary format
38+
* Support of TDS Versions 7.3, 7.4
3339

3440
## Connecting to SQL Instances
35-
Tds Supports sql instances by passing ```instance: "instancename"``` to the connection options.
36-
3741

42+
Tds supports SQL instances by passing `instance: "instancename"` to the connection options.
3843

3944
## Data representation
4045

41-
TDS Elixir
42-
---------- ------
43-
NULL nil
44-
bool true | false
45-
char "é"
46-
int 42
47-
float 42.0
48-
text "text"
49-
binary <<42>>
50-
numeric #Decimal<42.0> *
51-
date {2013, 10, 12}
52-
time {0, 37, 14}
53-
datetime {{2013, 10, 12}, {0, 37, 14}}
54-
uuid <<160,238,188,153,156,11,78,248,187,109,107,185,189,56,10,17>>
55-
56-
All data types will be supported, unsupported types currently are *User Defined Types*, xml
46+
| TDS | Elixir |
47+
| -------- | -------------------------------------------------------------- |
48+
| NULL | nil |
49+
| bool | true / false |
50+
| char | "é" |
51+
| int | 42 |
52+
| float | 42.0 |
53+
| text | "text" |
54+
| binary | <<42>> |
55+
| numeric | #Decimal<42.0> * |
56+
| date | {2013, 10, 12} |
57+
| time | {0, 37, 14} |
58+
| datetime | {{2013, 10, 12}, {0, 37, 14}} |
59+
| uuid | <<160,238,188,153,156,11,78,248,187,109,107,185,189,56,10,17>> |
60+
61+
Currently unsupported: [User-Defined Types](https://docs.microsoft.com/en-us/sql/relational-databases/clr-integration-database-objects-user-defined-types/working-with-user-defined-types-in-sql-server), XML
5762

5863
## Contributing
5964

60-
To contribute you need to compile Tds from source and test it:
65+
Clone and compile Tds with:
6166

62-
```
63-
$ git clone https://github.com/livehelpnow/tds.git
64-
$ cd tds
65-
$ mix test
67+
```bash
68+
git clone https://github.com/livehelpnow/tds.git
69+
cd tds
70+
mix deps.get
6671
```
6772

68-
The tests require your sql server database to be present on localhost. In case you are unable to run local instance of SQL server either using local installation on [windows](https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-installation-wizard-setup) or [linix](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup), docker image for [linux](https://hub.docker.com/r/microsoft/mssql-server-linux/)
73+
You can test the library with `mix test`. Use `mix credo` for linting and
74+
`mix dialyzer` for static code analysis. Dialyzer will take a while when you
75+
use it for the first time.
76+
77+
### SQL Server Setup
78+
79+
The tests require an sql server database to be available on localhost.
80+
81+
If you have Docker installed, you can use the official [SQL Server Docker image](https://hub.docker.com/r/microsoft/mssql-server-linux).
82+
To start the container, run:
83+
84+
```bash
85+
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=some!Password' -p 1433:1433 -d microsoft/mssql-server-linux:latest
86+
```
6987

88+
If you prefer to install SQL Server directly on your computer, you can find
89+
installation instructions here:
7090

71-
Additionally SQL authentication needs to be used for connecting and testing. Check config/test.exs file for credentials used in unit testing.
91+
* [Windows](https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-installation-wizard-setup)
92+
* [Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup)
7293

73-
##Special Thanks
94+
Make sure your SQL server accepts the credentials defined in `config/test.exs`.
7495

75-
Thanks to ericmj, this driver takes a lot of inspiration from postgrex.
76-
https://github.com/ericmj/
96+
You also will need to have the *sqlcmd* command line tools installed. Setup
97+
instructions can be found [here](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools).
7798

99+
## Special Thanks
78100

79-
Also thanks to everyone in the Elixir Google group and on the Elixir IRC Channel
101+
Thanks to [ericmj](https://github.com/ericmj), this driver takes a lot of inspiration from postgrex.
80102

103+
Also thanks to everyone in the Elixir Google group and on the Elixir IRC Channel.
81104

82105
## License
83106

84-
Copyright 2014, 2015, 2017 LiveHelpNow
107+
Copyright 2014, 2015, 2017 LiveHelpNow
85108

86-
Licensed under the Apache License, Version 2.0 (the "License");
87-
you may not use this file except in compliance with the License.
88-
You may obtain a copy of the License at
109+
Licensed under the Apache License, Version 2.0 (the "License");
110+
you may not use this file except in compliance with the License.
111+
You may obtain a copy of the License at
89112

90-
http://www.apache.org/licenses/LICENSE-2.0
113+
http://www.apache.org/licenses/LICENSE-2.0
91114

92-
Unless required by applicable law or agreed to in writing, software
93-
distributed under the License is distributed on an "AS IS" BASIS,
94-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95-
See the License for the specific language governing permissions and
96-
limitations under the License.
115+
Unless required by applicable law or agreed to in writing, software
116+
distributed under the License is distributed on an "AS IS" BASIS,
117+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
118+
See the License for the specific language governing permissions and
119+
limitations under the License.

config/test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ config :logger, level: :info
44

55
config :tds,
66
opts: [
7-
hostname: "localhost",
8-
username: "sa",
9-
password: "some!Password",
7+
hostname: System.get_env("SQL_HOSTNAME") || "127.0.0.1",
8+
username: System.get_env("SQL_USERNAME") || "sa",
9+
password: System.get_env("SQL_PASSWORD") || "some!Password",
1010
database: "test"
1111
]
1212

lib/tds.ex

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule Tds do
2-
32
alias Tds.Query
43

54
@timeout 5000
@@ -41,6 +40,7 @@ defmodule Tds do
4140
{:error, err} -> {:error, err}
4241
end
4342
end
43+
4444
def prepare!(pid, statement, opts \\ []) do
4545
query = %Query{statement: statement}
4646

@@ -56,6 +56,7 @@ defmodule Tds do
5656
{:error, err} -> {:error, err}
5757
end
5858
end
59+
5960
def execute!(pid, query, params, opts \\ []) do
6061
case DBConnection.execute(pid, query, params, opts) do
6162
{:ok, result} -> result
@@ -69,6 +70,7 @@ defmodule Tds do
6970
{:error, err} -> {:error, err}
7071
end
7172
end
73+
7274
def close!(pid, query, opts \\ []) do
7375
case DBConnection.close(pid, query, opts) do
7476
{:ok, result} -> result
@@ -77,10 +79,10 @@ defmodule Tds do
7779
end
7880

7981
def transaction(pid, fun, opts \\ []) do
80-
case DBConnection.transaction(pid, fun, opts) do
81-
{:ok, result} -> result
82-
err -> err
83-
end
82+
case DBConnection.transaction(pid, fun, opts) do
83+
{:ok, result} -> result
84+
err -> err
85+
end
8486
end
8587

8688
defdelegate rollback(conn, any), to: DBConnection
@@ -90,7 +92,6 @@ defmodule Tds do
9092
end
9193

9294
defp default(opts) do
93-
opts
94-
|> Keyword.put_new(:idle_timeout, @timeout)
95+
Keyword.put_new(opts, :idle_timeout, @timeout)
9596
end
9697
end

0 commit comments

Comments
 (0)