Implement column defaults for INSERT/UPDATE
This PR implements usage of column defaults from SQLAlchemy. In regular SQLAlchemy the default column values are fetched using ExecutionContext._exec_default. However, we don't use the ExecutionContext here, so a function is implemented to take its place for column defaults.
Fixes #72
Any updates on this?
It's difficult because I'm not really sure if we want this functionality or not.
@tomchristie I am just curious. Why would you not want this functionality? I am currently writing a application with fastapi and encode/databases and i want the timestamp to be created on insert. currently i don't have a way of doing this.
It also seems necessary for UUID primary keys, which are pretty common these days.
The column defaults are higher level sqla API ("Query") than the API used in databases ("Core"). Emulating them properly is quite hard. For example, the functions can access the context in several ways, and filling it is twisted.
The problem can be solved outside of databases package by adding a new method to your model base class to explicitly create defaults.
@vmarkovtsev SQLAlchemy core does have defaults, see the default parameter for Column.__init__. I agree that correctly emulating defaults is hard due to the types of things a column default can be (it can be a ClauseElement!), but that's no reason for it to not be included.
+1 for this. I followed the FastAPI tutorial and tried to implement a UUID for sqlite. I couldn't figure out why it didn't work until I specifically checked this repo for issues around the defaults. And defaults are indeed part of sqlalchemy core.
This is a must, thanks
Approve this pls
Any updates on this?