again timestamp field of postgres

35 views
Skip to first unread message

Sanjarbek Amatov

unread,
Nov 5, 2014, 12:20:33 AM11/5/14
to squ...@googlegroups.com
My problem with timestamp fields is continuing.

I am using play framework with squeryl. I am using Postgres.

In each db table I have two fields 'created_at' and 'updated_at'. Type of this fields is timestamp without timezone.
I am trying to find of automatically saving value of this fields using squeryl. 

New record saving in sql:
insert into test_table (name, created_at, updated_at)
values
('aaaa', LOCALTIMESTAMP, LOCALTIMESTAMP)


Update record in sql (changed name field value):
update test_table SET name='asdf', updated_at=LOCALTIMESTAMP
where id=100

How to implement this in squeryl??? Can I use postgres specific keywords like 'LOCALTIMESTAMP' ?
If not, please, direct me to right direction. 

David Whittaker

unread,
Nov 5, 2014, 1:41:30 PM11/5/14
to squ...@googlegroups.com
So if I'm understanding correctly, what you want to do is to make sure that insert's automatically contain a created_at date and updates always contain a proper updated_at date?

For the first case, the easiest way is to assign the current date to your createdAt field in the object constructor.

For updates, you can use lifecycle callbacks to intercept update calls on your model and set the correct value.  They are an undocumented feature but you can find more information here: https://groups.google.com/d/msg/squeryl/k8DDtF53D5A/rMi9Jg6vAgMJ

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages