3 ms·
I'm not sure what you think SQLalchemy can fix here? There has to be an option to pass a static default value and the library does not have a visibility into th
by viraptor 2y ago
I'm not sure what you think SQLalchemy can fix here? There has to be an option to pass a static default value and the library does not have a visibility into the parse tree. What's the proposed solution?
- dragonwriter 2y agoOne solution would be to have a separate default (static value) and default_factory (callable that returns a value) keyword argument, and make a static default on a PK (or other unique) column, by default, be an error.
- hipadev23 2y ago> I'm not sure what you think SQLalchemy can fix here Separate table definition (DDL) from row-insertion (DML) definitions along with their corresponding defaults.
- Nullabillity 2y ago> There has to be an option to pass a static default value Does there, though? You can always set `Column(default = lambda: 1234)`
- viraptor 2y agoYes, because you're creating a table and the value needs to be encoded as string in the CRATE TABLE query. You could in theory pass a lambda which is disassembled in SQLalchemy, then checked against the pattern returning a constant, then the constant itself gets used... But I'm not sure SQLalchemy would go that way. It's not as crazy as Linq. To be explicit: You're not seeing a function called later in python. You're setting an attribute on a database table.
- Nullabillity 2y agoNo[0], default= is inserted into the DML queries by the client. A DDL DEFAULT clause is only generated if you set server_default= instead. [0]: https://docs.sqlalchemy.org/en/20/core/defaults.html https://docs.sqlalchemy.org/en/20/core/defaults.html