Merge branch 'master' of github.com:seancorfield/next-jdbc
This commit is contained in:
commit
eed988896c
4 changed files with 25 additions and 2 deletions
|
|
@ -6,7 +6,7 @@ Only accretive/fixative changes will be made from now on.
|
||||||
|
|
||||||
The following changes have been committed to the **master** branch since the 1.0.6 release:
|
The following changes have been committed to the **master** branch since the 1.0.6 release:
|
||||||
|
|
||||||
* None.
|
* Added test for using `any(?)` and arrays in PostgreSQL for `IN (?,,,?)` style queries. Added a **Tips & Tricks** section to **Friendly SQL Functions** with database-specific suggestions, that starts with this one.
|
||||||
|
|
||||||
## Stable Builds
|
## Stable Builds
|
||||||
|
|
||||||
|
|
|
||||||
4
deps.edn
4
deps.edn
|
|
@ -17,7 +17,9 @@
|
||||||
com.opentable.components/otj-pg-embedded {:mvn/version "0.13.1"}
|
com.opentable.components/otj-pg-embedded {:mvn/version "0.13.1"}
|
||||||
com.impossibl.pgjdbc-ng/pgjdbc-ng {:mvn/version "0.8.2"}
|
com.impossibl.pgjdbc-ng/pgjdbc-ng {:mvn/version "0.8.2"}
|
||||||
org.xerial/sqlite-jdbc {:mvn/version "3.28.0"}
|
org.xerial/sqlite-jdbc {:mvn/version "3.28.0"}
|
||||||
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "7.2.2.jre8"}}}
|
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "7.2.2.jre8"}
|
||||||
|
;; supplementary test stuff
|
||||||
|
org.slf4j/slf4j-nop {:mvn/version "1.7.28"}}}
|
||||||
:runner
|
:runner
|
||||||
{:extra-deps {com.cognitect/test-runner
|
{:extra-deps {com.cognitect/test-runner
|
||||||
{:git/url "https://github.com/cognitect-labs/test-runner"
|
{:git/url "https://github.com/cognitect-labs/test-runner"
|
||||||
|
|
|
||||||
|
|
@ -162,4 +162,20 @@ These quoting functions can be provided to any of the friendly SQL functions abo
|
||||||
|
|
||||||
Note that the entity naming function is passed a string, the result of calling `name` on the keyword passed in. Also note that the default quoting functions do not handle schema-qualified names, such as `dbo.table_name` -- `sql-server` would produce `[dbo.table_name]` from that. Use the `schema` function to wrap the quoting function if you need that behavior, e.g,. `{:table-fn (schema sql-server)}` which would produce `[dbo].[table_name]`.
|
Note that the entity naming function is passed a string, the result of calling `name` on the keyword passed in. Also note that the default quoting functions do not handle schema-qualified names, such as `dbo.table_name` -- `sql-server` would produce `[dbo.table_name]` from that. Use the `schema` function to wrap the quoting function if you need that behavior, e.g,. `{:table-fn (schema sql-server)}` which would produce `[dbo].[table_name]`.
|
||||||
|
|
||||||
|
## Tips & Tricks
|
||||||
|
|
||||||
|
This section will accrue various tips and tricks that make it easier to use `next.jdbc` with a variety of databases. It will be organized by database.
|
||||||
|
|
||||||
|
## MySQL
|
||||||
|
|
||||||
|
MySQL generally stores tables as files so they are case-sensitive if your O/S is (Linux) or case-insensitive if your O/S is not (Mac, Windows) but the column names are generally case-insensitive. This can matter when if you use `next.jdbc.result-set/as-lower-maps` because that will lower-case the table names (as well as the column names) so if you are round-tripping based on the keys you get back, you may produce an incorrect table name in terms of case. You'll also need to be careful about `:table-fn`/`:column-fn` because of this.
|
||||||
|
|
||||||
|
It's also worth noting that column comparisons are case-insensitive so `WHERE foo = 'BAR'` will match `"bar"` or `"BAR"` etc.
|
||||||
|
|
||||||
|
### PostgreSQL
|
||||||
|
|
||||||
|
If you have a query where you want to select where a column is `IN` a sequence of values, you can use `col = ANY(?)` with a native array of the values instead of `IN (?,?,?,,,?)` and a sequence of values.
|
||||||
|
|
||||||
|
What does this mean for your use of `next.jdbc`? In `plan`, `execute!`, and `execute-one!`, you can use `col = ANY(?)` in the SQL string and a single primitive array parameter, such as `(int-array [1 2 3 4])`. That means that in `next.jdbc.sql`'s functions that take a where clause (`find-by-keys`, `update!`, and `delete!`) you can specify `["col = ANY(?)" (int-array data)]` for what would be a `col IN (?,?,?,,,?)` where clause for other databases and require multiple values.
|
||||||
|
|
||||||
[<: Getting Started](/doc/getting-started.md) | [Result Set Builders :>](/doc/result-set-builders.md)
|
[<: Getting Started](/doc/getting-started.md) | [Result Set Builders :>](/doc/result-set-builders.md)
|
||||||
|
|
|
||||||
|
|
@ -197,3 +197,8 @@
|
||||||
(sql/find-by-keys (ds) :fruit
|
(sql/find-by-keys (ds) :fruit
|
||||||
{:name "Apple"}
|
{:name "Apple"}
|
||||||
{:order-by []}))))
|
{:order-by []}))))
|
||||||
|
|
||||||
|
(deftest array-in
|
||||||
|
(when (postgres?)
|
||||||
|
(let [data (sql/find-by-keys (ds) :fruit ["id = any(?)" (int-array [1 2 3 4])])]
|
||||||
|
(is (= 4 (count data))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue