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

where* doesn't work with maps #137

Open
asyntactic opened this issue Apr 1, 2013 · 1 comment
Open

where* doesn't work with maps #137

asyntactic opened this issue Apr 1, 2013 · 1 comment

Comments

@asyntactic
Copy link

I may be misunderstanding the use of the * functions in korma.core, but I can't get where* to work with a map, as described in the API docs.

This works:
(-> (select* users)
(where* "username = 'tom'")
select)

However, this doesn't:
(-> (select* users)
(where* {:username "tom"})
select)

The error message indicates that where* is inserting some intermediate form of the clause into the query, instead of rendering it as the SQL text:

Failure to execute query with SQL:
SELECT "users".* FROM "users" WHERE {:korma.sql.utils/pred #<engine$do_group korma.sql.engine$do_group@3c200d0>, :korma.sql.utils/args [" AND " ({:korma.sql.utils/pred #<engine$do_infix korma.sql.engine$do_infix@e99fb6>, :korma.sql.utils/args [{:korma.sql.utils/generated ""users"."username""} "=" "tom"]})]} :: []
PSQLException:
Message: ERROR: syntax error at or near "{"
Position: 37
SQLState: 42601
Error Code: 0

@sgrove
Copy link
Contributor

sgrove commented Oct 8, 2013

It looks like you can simply use where in this case:

(let [organization-id nil
      service "korma"
      query {:service service}
      query (if organization-id
              (assoc query :organization_id organization-id)
              query)]

  (-> (korm/select* db/oauth-tokens)
      (korm/where query)
      (korm/as-sql)
      println))
;; SELECT "oauth_tokens".* FROM "oauth_tokens" WHERE ("oauth_tokens"."service" = ?)

(let [organization-id 3
      service "korma"
      query {:service service}
      query (if organization-id
              (assoc query :organization_id organization-id)
              query)]

  (-> (korm/select* db/oauth-tokens)
      (korm/where query)
      (korm/as-sql)
      println))
;; SELECT "oauth_tokens".* FROM "oauth_tokens" WHERE ("oauth_tokens"."organization_id" = ? AND "oauth_tokens"."service" = ?)

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

No branches or pull requests

2 participants