Home

Awesome

Jamdb.Oracle

Erlang driver and Ecto adapter for Oracle Database

Features

Options

Adapter options split in different categories described below. All options can be given via the repository configuration:

config :your_app, YourApp.Repo,
  ...

Connection options

Pool options

Connection parameters

Output parameters

Oracle typesLiteral syntax in params
NUMBER,FLOAT,BINARY_FLOAT:number, :integer, :float, :decimal
CHAR, VARCHAR2, CLOB:varchar, :char, :clob, :string
NCHAR, NVARCHAR2, NCLOB:nvarchar, :nchar, :nclob
RAW, BLOB:raw, :blob, :binary, :hexstring
DATE:date
TIMESTAMP:timestamp
TIMESTAMP WITH TIME ZONE:timestamptz
SYS_REFCURSOR:cursor

Input parameters

Using query options: [in: [:number, :binary]]

Primitive types

The primitive types are:

Ecto typesOracle typesLiteral syntax in params
:id, :integerNUMBER (*,0), INTEGER1, 2, 3
:floatNUMBER,FLOAT,BINARY_FLOAT1.0, 2.0, 3.0
:decimalNUMBER,FLOAT,BINARY_FLOATDecimal
:stringCHAR, VARCHAR2, CLOB"one hundred"
:stringNCHAR, NVARCHAR2, NCLOB"百元", "万円"
:binaryRAW, BLOB"E799BE" (base 16 encoded)
:binaryRAW, BLOB<<0xE7,0x99,0xBE>> (option [in: [:binary])
:binary_idRAW, BLOB<<231,153,190, ...>> (option [in: [:binary_id])
:booleanCHAR, VARCHAR2, NUMBERtrue, false
:mapCLOB, NCLOB%{"one" => 1, "hundred" => "百"}
:naive_datetimeDATE, TIMESTAMPNaiveDateTime
:utc_datetimeTIMESTAMP WITH TIME ZONEDateTime

Character sets

String in Elixir is UTF-8 encoded binary.

:us7ascii, :we8iso8859p1, :ee8iso8859p2, :nee8iso8859p4, :cl8iso8859p5, :ar8iso8859p6, :el8iso8859p7,:iw8iso8859p8, :we8iso8859p9, :ne8iso8859p10, :th8tisascii, :vn8mswin1258, :we8iso8859p15,:blt8iso8859p13, :ee8mswin1250, :cl8mswin1251, :el8mswin1253, :iw8mswin1255, :tr8mswin1254,:we8mswin1252, :blt8mswin1257, :ar8mswin1256

:ja16euc, :ja16sjis, :ja16euctilde,:ja16sjistilde,:ko16mswin949, :zhs16gbk, :zht32euc, :zht16big5, :zht16mswin950, :zht16hkscs

Examples

iex> Ecto.Adapters.SQL.query(YourApp.Repo, "select 1+:1,sysdate,rowid from dual where 1=:1 ", [1])
{:ok, %{num_rows: 1, rows: [[2, ~N[2016-08-01 13:14:15], "AAAACOAABAAAAWJAAA"]]}}

iex> row = [%Ecto.Query.Tagged{value: <<0xE7,0x99,0xBE>>, type: :binary}]
iex> Ecto.Adapters.SQL.query(YourApp.Repo, "insert into tabl values (:1)", row)

iex> row = [%Ecto.Query.Tagged{value: %{dat: {2023, 1, 1}, id: 1}, type: :map}]
iex> Ecto.Adapters.SQL.query(YourApp.Repo, "insert into tabl values (:id, :dat)", row)
    
iex> opts = [batch: true, in: [Ecto.UUID, :number]]
iex> row = [Ecto.UUID.bingenerate, 1]
iex> Ecto.Adapters.SQL.query(YourApp.Repo, "insert into tabl values (:1, :2)",
...> [row, row], opts)
    
iex> opts = [returning: false, out: [:integer]]
iex> row = [Date.utc_today]
iex> Ecto.Adapters.SQL.query(YourApp.Repo, "insert into tabl (dat) values (:1) return id into :2",
...> row, opts)

Using quoted identifiers:

defmodule YourApp.Users do
  use Ecto.Schema

  schema "\\"USERS\\"" do
    field :id, :integer
    field :uuid, :binary_id
    field :name, :string, source: :'"NAME"'
    field :namae, :string, source: :'"名まえ"'
  end

end

iex> YourApp.Repo.all(from(u in "\\"USERS\\"", select: u.'"NAME"', where: u.id == 1))

iex> YourApp.Repo.all(from(u in YourApp.Users, select: u.namae, where: u.id == 1))

iex> uuid = "601d74e4-a8d3-4b6e-8365-eddb4c893327"
iex> YourApp.Repo.all(from(u in YourApp.Users, select: u.name,
iex> where: u.uuid == type(^uuid, :binary_id)), [in: [:binary_id]])

Imagine you have this migration:

defmodule YourApp.Repo.Migrations.Users do
  use Ecto.Migration

  def change do
    create table(:users, comment: "users table") do
      add :name, :string, comment: "name column"
      add :namae, :string, national: true
      add :custom_id, :uuid
      timestamps()
    end
  end

end

To migrate you'd do it normally:

$ mix ecto.migrate