Insert values that use SQL functions #3

Closed
ninjudd opened this Issue Feb 20, 2014 · 14 comments

Projects

None yet

2 participants

@ninjudd
Contributor
ninjudd commented Feb 20, 2014

Is there a way to insert values that depend on SQL?

For example, I'd like to do something like:

(insert :tokens []
  {:value 123, :expires-at `(+ (now) ~interval)})
@r0man
Owner
r0man commented Feb 21, 2014

Hi Justin,
this is not possible at the moment.
Roman

@ninjudd
Contributor
ninjudd commented Feb 21, 2014

Thanks @r0man. I figured out a better way to do what I need in this case (store an expiry column as a postgres interval instead of expires_at). If I need SQL insert values in the future, I'll dive into the code and see if I can figure out how to add them.

By the way, this is a great library! Thanks. I spent yesterday converting my app to SQLingvo, and it is an absolute pleasure to use.

@r0man
Owner
r0man commented Feb 21, 2014

Hi Justin,

I'm glad you found a solution for that. I already thought about
interpreting symbols in the value position of a map as SQL
expressions for the UPDATE statement. The same strategy should be
applied to the INSERTs as well. I'll take a look at it, if I have
time. Just curious, what did you use before SQLingvo?

Roman

On Fri, Feb 21, 2014 at 6:51 PM, Justin Balthrop
notifications@github.comwrote:

Thanks @r0man https://github.com/r0man. I figured out a better way to
do what I need in this case (store an expiry column as a postgres
interval instead of expired_at). If I need SQL insert values in the
future, I'll dive into the code and see if I can figure out how to add them.

By the way, this is a great library! Thanks. I spent yesterday converting
my app to SQLingvo, and it is an absolute pleasure to use.

Reply to this email directly or view it on GitHubhttps://github.com/r0man/sqlingvo/issues/3#issuecomment-35755009
.

@ninjudd
Contributor
ninjudd commented Feb 21, 2014

I was using Korma.

On previous projects, I have also used ClojureQL v2 (I helped Lau with some of the API) and java.jdbc directly.

@ninjudd
Contributor
ninjudd commented Aug 19, 2014

@r0man looks like I'm at a point where I need this for UPDATE. SQLingvo still does not support this right?

@r0man
Owner
r0man commented Aug 19, 2014

Hi Justin, no it's still not implemented. I'm also on holiday the next
weeks, so I will not have time to look into this myself.
On 19 Aug 2014 19:22, "Justin Balthrop" notifications@github.com wrote:

@r0man https://github.com/r0man looks like I'm at a point where I need
this for UPDATE. SQLingvo still does not support this right?


Reply to this email directly or view it on GitHub
#3 (comment).

@ninjudd
Contributor
ninjudd commented Oct 9, 2014

@r0man any tips on where to start with this? I've put it off as long as possible, but now I need to be able to update a row to append an element to a postgres array. Something like:

(update :item `[(= :tags (|| :tags ~tag))]
  (where `(= :id ~id)))

Or even better:

(update :item `[(=|| :tags ~tag))]
  (where `(= :id ~id)))
@r0man
Owner
r0man commented Oct 10, 2014

Hey Justin,

I had something like this in mind for insert statement

(insert :films [:name]
  (values {:name '(lower "X")}))

and this for update statements

(update :films {:name '(lower "X")}
  (where `(= :id 1)))

To get started I think we would need to make sure the values of the
hash map passed to inser/update are parsed via parse-expr to convert
them to the proper AST structures used elsewhere.

What do you think?

Roman

@ninjudd
Contributor
ninjudd commented Oct 10, 2014

That sounds good. Does this mean the first update statement I posted above will work now?

@r0man
Owner
r0man commented Oct 10, 2014

Hi Justin,

I have a branch over here where I played around a bit.

https://github.com/r0man/sqlingvo/tree/insert-update-fn

Unforntunatly it's not ready yet. Lot's of things are breaking
with these changes. I'm traveling/working at the moment, so I
can't promise to work on that feature yet. If you want to take a
look into this yourself and need any help, ping me.

The compiler got also a bit out of control I fear :)

Roman

@ninjudd
Contributor
ninjudd commented Oct 10, 2014

Interesting. I got to the point of adding parse-map-expr and calling it in values, but that wasn't enough, obviously. Seems like calling parse-map-expr on row in update may work though.

@ninjudd
Contributor
ninjudd commented Oct 10, 2014

Nope. Getting the same type of error I got with insert...

@r0man
Owner
r0man commented Oct 12, 2014

@ninjudd Can you give the latest changes in the insert-update-fn branch a try. The statements mentioned above should compile now ...

@r0man
Owner
r0man commented Jun 15, 2016

Closing this issue, since this has been merged a while ago ...

@r0man r0man closed this Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment