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

defaultTo now() / CURRENT_DATE / CURRENT_TIMESTAMP #146

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

defaultTo now() / CURRENT_DATE / CURRENT_TIMESTAMP #146

tkellen opened this issue Jan 7, 2014 · 10 comments

Comments

@tkellen
Copy link
Contributor

@tkellen 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
Copy link
Member

@tgriesser 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
Copy link
Contributor Author

@tkellen tkellen commented Jan 7, 2014

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

@tgriesser
Copy link
Member

@tgriesser tgriesser commented Jan 7, 2014

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

@tkellen
Copy link
Contributor Author

@tkellen 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
Fix for #146, allowing knex.raw in defaultTo
@tgriesser
Copy link
Member

@tgriesser 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
Copy link
Contributor Author

@tkellen tkellen commented Jan 8, 2014

beautiful, thanks!

@kevin-romens
Copy link

@kevin-romens 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
Copy link
Member

@rhys-vdw 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
Copy link
Collaborator

@jurko-gospodnetic jurko-gospodnetic commented May 16, 2016

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

@kevin-romens
Copy link

@kevin-romens 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants