ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - livehelpnow/tds_ecto: TDS Adapter for Ecto
TDS Adapter for Ecto. Contribute to livehelpnow/tds_ecto development by creating an account on GitHub.
Visit Site

GitHub - livehelpnow/tds_ecto: TDS Adapter for Ecto

GitHub - livehelpnow/tds_ecto: TDS Adapter for Ecto

Tds.Ecto (Ecto v2)

MSSQL / TDS Adapter for Ecto2

Build Status Hex Version

Example

# In your config/config.exs file add MSSQL connection options
# By default it use port 1433, different port can be specified with
# port: 1434
# option and named instance with
# instance: "instance_name"
config :my_app, Repo,
  database: "ecto_simple",
  username: "mssql",
  password: "mssql",
  hostname: "localhost"

# In your application code
defmodule Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Tds.Ecto
end

defmodule Weather do
  use Ecto.Schema

  schema "weather" do
    field :city     # Defaults to type :string
    field :temp_lo, :integer
    field :temp_hi, :integer
    field :prcp,    :float, default: 0.0
  end
end

defmodule Simple do
  import Ecto.Query

  def sample_query do
    query = from w in Weather,
          where: w.prcp > 0 or is_nil(w.prcp),
         select: w
    Repo.all(query)
  end
end

Also, if you need to map table to schema other than [dbo], simple use @schema_prefix "your_schema", eg:

defmodule Invoices.Invoice do
  use Ecto.Schema

  @schema_prefix :invoices
  schema "invoices" do
    field :due_date, :datetime
    field :sum, :float
  end
end

Usage

Add Tds as a dependency in your mix.exs file.

def deps do
  [{:tds_ecto, "~> 2.2"}]
end

You should also update your applications list to include both projects:

def application do
  [applications: [:logger, :tds_ecto, :ecto]]
end

To use the adapter in your repo:

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Tds.Ecto
end

tds_ecto relies on pattern matching against error messages to extract constraint names. If your SQL server is not configured to English as its default language you may add an after_connect hook to your repo and set English as the language for Ecto connections.

def after_connect(conn) do
  Tds.Ecto.Connection.query(conn, "SET LANGUAGE English", [], [])
end

For additional information on usage please see the documentation for Ecto.

Data Type Mapping

MSSQL             	Ecto/Tds.Ecto
----------        	------
nvarchar            :string
varchar             Tds.VarChar
char                :binary
varbinary           :binary
float               :float
decimal             :decimal
integer             :integer
bit                 :boolean
uniqueidentifier    :uuid
datetime            :datetime
date                :date
time                :time

Contributing

To contribute you need to compile Tds from source and test it:

$ git clone https://github.com/livehelpnow/tds_ecto.git
$ cd tds_ecto
$ mix test

Tests will try to connect to localhost using sa as username with predefined password mssql, but you can set environment variables to override any, like so: SQL_USERNAME=myuser; SQL_PASSWORD=mypassword; SQL_HOSTNAME=sqlserver.local; mix test or if you are using windows then SET SQL_USERNAME=myuser && SET SQL_PASSWORD=mypassword && SET SQL_HOSTNAME=sqlserver.local && mix test. Please note that tests will run againes default sql server instance.

Additionally SQL authentication needs to be used for connecting and testing.If you override default test settings, make sure either that yor user has sysadmin privilegies to add the user test_user with access to the database test_db, or simply add manualy test_user on your server. See one of the test files for the connection information and port number.

License

Copyright 2014, 2015, 2016, 2017 LiveHelpNow

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory