korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Table name in postgres is Users, and Korma doesn't seem to add quotes around table name. #321

Closed base698 closed 8 years ago

base698 commented 8 years ago

leiningen.web=> (defentity Users)

'leiningen.web/Users

leiningen.web=> (select Users (where {:id 61}) (limit 1)) Failure to execute query with SQL: SELECT Users.* FROM Users WHERE (Users.id = ?) LIMIT 1 :: [61] PSQLException: Message: ERROR: relation "users" does not exist Position: 21 SQLState: 42P01 Error Code: 0

PSQLException ERROR: relation "users" does not exist Position: 21 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

immoh commented 8 years ago

Can't repro with this information. How do you define your db?

Quotes should be added by default:

(defdb mydb (postgres {}))
;;=> {:pool #<Delay@71135d3b: :pending>, :options {:naming {:keys #<core$identity clojure.core$identity@770c23aa>, :fields #<core$identity clojure.core$identity@770c23aa>}, :delimiters ["\"" "\""], :alias-delimiter " AS ", :subprotocol "postgresql"}}
(defentity Users)
;;=> #'user/Users
(sql-only (select Users (where {:id 61}) (limit 1)))
;;=> "SELECT \"Users\".* FROM \"Users\" WHERE (\"Users\".\"id\" = ?) LIMIT 1"
base698 commented 8 years ago

Mine says :delimiters [nil nil] for the line where yours says :delimiters ["\"" "\""]

How do you define the delimiters? Using defdb I have :delimiters ""

I tried :delimiters ["\"" "\""] as well.

On Thu, Jul 30, 2015 at 1:37 AM, Immo Heikkinen notifications@github.com wrote:

Can't repro with this information. How do you define your db?

Quotes should be added by default:

(defdb mydb (postgres {}));;=> {:pool #<Delay@71135d3b: :pending>, :options {:naming {:keys #<core$identity clojure.core$identity@770c23aa>, :fields #<core$identity clojure.core$identity@770c23aa>}, :delimiters ["\"" "\""], :alias-delimiter " AS ", :subprotocol "postgresql"}} (defentity Users);;=> #'user/Users (sql-only (select Users (where {:id 61}) (limit 1)));;=> "SELECT \"Users\".* FROM \"Users\" WHERE (\"Users\".\"id\" = ?) LIMIT 1"

— Reply to this email directly or view it on GitHub https://github.com/korma/Korma/issues/321#issuecomment-126225688.

base698 commented 8 years ago

Never mind, if you don't specify it works fine :)

On Thu, Jul 30, 2015 at 10:37 AM, Justin Thomas justin.thomas1@gmail.com wrote:

Mine says :delimiters [nil nil] for the line where yours says :delimiters ["\"" "\""]

How do you define the delimiters? Using defdb I have :delimiters ""

I tried :delimiters ["\"" "\""] as well.

On Thu, Jul 30, 2015 at 1:37 AM, Immo Heikkinen notifications@github.com wrote:

Can't repro with this information. How do you define your db?

Quotes should be added by default:

(defdb mydb (postgres {}));;=> {:pool #<Delay@71135d3b: :pending>, :options {:naming {:keys #<core$identity clojure.core$identity@770c23aa>, :fields #<core$identity clojure.core$identity@770c23aa>}, :delimiters ["\"" "\""], :alias-delimiter " AS ", :subprotocol "postgresql"}} (defentity Users);;=> #'user/Users (sql-only (select Users (where {:id 61}) (limit 1)));;=> "SELECT \"Users\".* FROM \"Users\" WHERE (\"Users\".\"id\" = ?) LIMIT 1"

— Reply to this email directly or view it on GitHub https://github.com/korma/Korma/issues/321#issuecomment-126225688.

immoh commented 8 years ago

Great :smile: