Skip to content
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

V1.0.0 #64

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

V1.0.0 #64

wants to merge 33 commits into from

Conversation

PM-Pepsico
Copy link
Contributor

This reconfigures most of our connection handling to follow the Ecto.Adapters.SQL.Connection behavior. This allows queries to be constructed using Ecto schemas and the Ecto.Query macros.

An Ecto Repo for querying can now be created by defining a module like so:

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

Compatibility with previous versions of snowflake is possible by adding an execute function to this Repo module which will use the new API and translate the results to how they were returned previously like so:

    def execute(query, params \\ [], opts \\ []) do
      %Snowflex.Result{columns: columns, rows: rows} = __MODULE__.query!(query, params, opts)

      bin_headers =
        columns
        |> Enum.map(fn header -> header |> to_string() |> String.downcase() end)
        |> Enum.with_index()

      Enum.map(rows, fn row ->
        Enum.reduce(bin_headers, %{}, fn {col, index}, map ->
          data =
            row
            |> Enum.at(index)

          Map.put(map, col, data)
        end)
      end)
    end

PM-Pepsico and others added 11 commits December 9, 2022 13:06
This reconfigures most of our connection handling to follow the Ecto.Adapters.SQL.Connection behavior. This allows queries to be constructed using Ecto schemas and the Ecto.Query macros.

An Ecto Repo for querying can now be created by defining a module like so:
```
defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Snowflex.EctoAdapter
end
```

Compatibility with previous versions of snowflake by adding an execute function to this Repo module which will use the new API and translate to results to how they were returned previously like so:
```
    def execute(query, params \\ [], opts \\ []) do
      %Snowflex.Result{columns: columns, rows: rows} = __MODULE__.query!(query, params, opts)

      bin_headers =
        columns
        |> Enum.map(fn header -> header |> to_string() |> String.downcase() end)
        |> Enum.with_index()

      Enum.map(rows, fn row ->
        Enum.reduce(bin_headers, %{}, fn {col, index}, map ->
          data =
            row
            |> Enum.at(index)

          Map.put(map, col, data)
        end)
      end)
    end
```
We add a migration generator module which provides a macro to generate the migrations needed to test any Ecto Schema.
This allows you to swap in another Ecto adapter for local testing without connecting to Snowflake.

To use this you can bring the Snowflex.SQLiteTestRepo into your project and use it as you normally would for testing.
You will need to drop and create the repo before starting the tests each time so the migrations can work from a blank slate.

You will also need to run the generate_migrations macro in your test_helper files with a list of all the Ecto Schemas you wish to test.
The Erlang odbc api does not allow for params to be passed when using a cursor.

Users can get around this limitation by passing arguments embedded as string directly in their query using the fragment function in Ecto.Query.API
ODBC requires unicode params to be sent as :sql_wvarchar and encoded as UTF-16.
This sends all strings in this format by default to support unicode.
Because `nil` is technically an atom, we need to ensure that it gets encoded before we attempt to encode other atoms as `sql_varchars`.  This commit moves the `nil` case clause to a more appropriate location.
If the auto_commit mode has been turned off we now send a rollback message to each process before a disconnect so ODBC can gracefully end the connection.
We weren't actually checking if the auto_commit mode was off, so we were never sending commit commands to odbc.
This fixes the issue.
dustinfarris and others added 6 commits January 24, 2023 09:08
This enables a multi-statement query, e.g. "select 1; select 2".
Pinning sqlite3 to a specific version can break downstream applications
in a way that is not strictly necessary.
This keeps the compiler happy if we're in a project or environment in
which the user has chosen not to opt in to sqlite3 usage.
These connection options are only needed when establishing a new connection
and they are retrieved from config at that time.

This ensures that sensitive information is not logged when
a snowflex connection crashes.

fixes DAPPS-2084
kellyfelkins and others added 11 commits April 5, 2023 09:46
…tive-data-from-logs

 remove sensitive data from logs
Handles instances where date may be wrapped in an additional call, such as `Ecto.Query.API.max/1`.

Example:

```
from(s in MySchema, select_merge: %{my_date: max(s.my_date)})
|> MyRepo.all()
```
feat(ecto_adapter): cast maybe dates to date
In Ecto 3.11, adapters now handle decoding with nil values, originating from null values in records.
chore(ecto_adatper):  Update decoding behavior in adapters for Ecto 3.11
## Context

```
warning: single-quoted strings represent charlists. Use ~c"" if you indeed want a charlist or use "" instead
     │
 256 │   defp insert_all_value(_), do: '?'
     │                                 ~
     │
     └─ lib/snowflex/ecto/connection.ex:256:33

     warning: single-quoted strings represent charlists. Use ~c"" if you indeed want a charlist or use "" instead
     │
 601 │     '?'
     │     ~
     │
     └─ lib/snowflex/ecto/connection.ex:601:5
```
## Context

ecto release v1.12.1 introduced a change to the way mappings were return for `Ecto.Enum.mappings/2`.

We were relying on this mapping to convert Ecto.Enum to `:string` when creating the database columns.

See elixir-ecto/ecto@21c6068#diff-025069044568b480ef6f86f025cb46a7064695e6df1e7008ede689e09a9c7836L317-R318

## Decision

To make this more future proof, use `Ecto.Type.type/1` to handle schema type to database type conversions.
chore: use Ecto.Type.type to determine db type
…ixes"

This reverts commit 77a50be, reversing
changes made to b6eb28c.
…ges-ecto-type

Revert "Merge pull request #81"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants