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

defaultTo now() / CURRENT_DATE / CURRENT_TIMESTAMP #146

Closed
tkellen opened this Issue Jan 7, 2014 · 10 comments

Comments

Projects
None yet
5 participants
@tkellen
Collaborator

tkellen commented Jan 7, 2014

First, thanks for the great work on this module!

Second, is this presently possible in the schema builder in some form I'm not aware of?

@tgriesser

This comment has been minimized.

Owner

tgriesser commented Jan 7, 2014

Thanks! I think it should be if you do defaultTo(knex.raw('now()')) etc. Let me know if that doesn't work, I'm in the process of doing a huge refactor to make more consistent use of raw, sub selects, etc throughout the library.

@tkellen

This comment has been minimized.

Collaborator

tkellen commented Jan 7, 2014

Sadly no! It produces this: TypeError: Converting circular structure to JSON

@tgriesser

This comment has been minimized.

Owner

tgriesser commented Jan 7, 2014

Ah shoot... I'll have to take a look at it sometime tomorrow.

@tkellen

This comment has been minimized.

Collaborator

tkellen commented Jan 7, 2014

Thanks Tim! I really appreciate the super fast response.

tgriesser added a commit that referenced this issue Jan 8, 2014

tgriesser added a commit that referenced this issue Jan 8, 2014

Merge pull request #147 from tgriesser/defaultTo-raw
Fix for #146, allowing knex.raw in defaultTo
@tgriesser

This comment has been minimized.

Owner

tgriesser commented Jan 8, 2014

Alright, should be good to go and out on 0.5.4 - let me know if you see any other issues... Thanks!

@tgriesser tgriesser closed this Jan 8, 2014

@tkellen

This comment has been minimized.

Collaborator

tkellen commented Jan 8, 2014

beautiful, thanks!

@kevin-romens

This comment has been minimized.

kevin-romens commented May 16, 2016

@tgriesser hi ,I wanna build sql like this :
select name ,age, year(curDate())-year(birthDate)) as age from Student.

the mysql inner function curDate() must use raw,but I don't know how to connect with select , could you please help me ? thanks ~~~

@rhys-vdw

This comment has been minimized.

Collaborator

rhys-vdw commented May 16, 2016

@kevin-romens please open new issues in future, this has been closed for two and a half years (and is off topic).

knex('Student').select(
  'name',
  'age',
  knex.raw('(year(curDate()) - year(birthDate)) as age')
)
@jurko-gospodnetic

This comment has been minimized.

Collaborator

jurko-gospodnetic commented May 16, 2016

Probably just a typo - but this would define two columns with the same name age.

@kevin-romens

This comment has been minimized.

kevin-romens commented May 20, 2016

@rhys-vdw got it . thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment