Skip to content

I want to use named params in `Ecto.Adapters.SQL.Query` so I try make this.

License

Notifications You must be signed in to change notification settings

Nao000/NamedBindSql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NamedBindSql

example

  1. prepare sql with named params.
    • sql = "SELECT * FROM table1 AS t1 WHERE t1.id = :id AND t1.created_at = :created_at AND t1.id = :id;"
  2. prepare params map
    • params = %{"id" => 1000, "created_at" => "2021-02-28 00:00:00"}
  3. execute
    • {sql_doller, param_list} = NamedBindSql.prepare_sql_with_params(sql, params)
  4. result
    {
      "SELECT * FROM table1 AS t1 WHERE t1.id = $1 AND t1.created_at = $2 AND t1.id = $1 ;",
      [1000, "2021-02-28 00:00:00"]
    }
  5. use in Ecto.Adapters.SQL.Query
    {sql_doller, param_list} = NamedBindSql.prepare_sql_with_params(sql, params)
    
    Ecto.Adapters.SQL.Query(Yourapp.Repo, sql_doller, param_list)

Installation

If available in Hex, the package can be installed by adding named_bind_sql to your list of dependencies in mix.exs:

def deps do
  [
    {:named_bind_sql, "~> 0.2.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/named_bind_sql/.

About

I want to use named params in `Ecto.Adapters.SQL.Query` so I try make this.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages