Toucan put a string as table name in sql using mysql
- Dominant language
- Clojure
- Stars
- 576
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
Hi @camsaul,
I'm playing with Toucan, connecting to a mysql db.
I configured Toucan to work with `hikari` datasource and `mount`:
```clojure
(ns reviews.database
(:require [hikari-cp.core :as h]
[mount.core :refer [defstate]]
[toucan.models :refer [set-root-namespace!]]
[toucan.db :refer [set-default-db-connection!]]))
;move to configuration
(def datasource-options {:auto-commit true
:read-only false
:connection-timeout 30000
:validation-timeout 5000
:idle-timeout 600000
:max-lifetime 1800000
:minimum-idle 1
:maximum-pool-size 10
:pool-name "db-pool"
:adapter "mysql"
:username "root"
:password "root"
:database-name "reviews-app"
:server-name "localhost"
:port-number 3306
:register-mbeans false})
(defn- create-datasource []
(doto {:datasource (h/make-datasource datasource-options)}
(set-default-db-connection!)))
(defstate database
:start (create-datasource)
:stop (h/close-datasource (database :datasource)))
(set-root-namespace! 'reviews.models)
```
Having my model:
```clojure
(ns reviews.models.review
(:require [toucan.models :refer [defmodel]]))
(defmodel Review :reviews)
```
When I do:
```clojure
user=> (t/debug-print-queries
(t/select 'Review))
;output
; {:select [:*],
; :from [{:table :reviews, :name "Review", :toucan.models/model true}]}
; nil
; SELECT *
; FROM "reviews"
; null
```
I get the following exception:
> Execution error (MySQLSyntaxErrorException) at
> jdk.internal.reflect.NativeConstructorAccessorImpl/newInstance0 (NativeConstructorAccessorImpl.java:-2).
>
> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"reviews"' at line 1
class com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
The issue is that it writes the table name as `"reviews"` instead of `review`.
Have I misconfigured something or is this some sort of bug?
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the query using `defmodel Review :reviews`, `t/select 'Review`, and `t/debug-print-queries` against the configured MySQL datasource. Start by tracing how Toucan builds the `:from` table and renders the SQL; the issue is done when the generated query is accepted by MySQL and the table reference matches the model configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure, mysql, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100