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

Support createdAt and updatedAt fields for database types #907

Open
ramnivas opened this issue Sep 17, 2023 · 1 comment
Open

Support createdAt and updatedAt fields for database types #907

ramnivas opened this issue Sep 17, 2023 · 1 comment
Labels

Comments

@ramnivas
Copy link
Contributor

We already sort of support createdAt through default value, but we need a concept of readonly fields to make it semantically correct.

type Todo {
  ...
  createAt: Instant = now()
}

But here, API still allows specifying a new value. If we enable marking this field as readonly (or an equivalent syntax), this will make it sound.

For updatedAt, the same idea works as long as developers have defined a trigger. But we may want to support that more directly (by creating a trigger during schema generation).

Note that while the interceptor mechanism can also work, a trigger is a better solution in the environment where the database is accessed by clients other than an Exograph-based server.

@shiftlabs1
Copy link

shiftlabs1 commented Sep 17, 2023

I think if triggers can be "attributified", that will be nice . for e.g
if i have a type Todo

@access(true)
@before-insert('name-of-function')     
type Todo {
@pk id: Uuid = generate_uuid()
  description: String 
  createdAt: LocalDatetime = now()
updatedAt: LocalDateTime = now()
}

other attribute will be @after-insert , @before-update @after-update
We can have the function already in the DB or define it as a postgres modeul type (this will also cater to views ) with defined paratemeter and return types if any . Such trigger function can then be shared across the schema .
N.B i.sona from Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants