Comments (2)
A great question! We certainly need to document this, but here are a few solutions at the moment:
- Use
unsafeLiteral "DEFAULT"
, as you mentioned. We haven't exported this as a definition (e.g.,defaultValue = unsafeLiteral "DEFAULT"
) due to its, well, unsafeness. - Don't rely on the default at all, and instead write an actual expression. In this case I don't know what the default of
position
would be, but in the typical case of wanting an auto-incremented id, you can use https://hackage.haskell.org/package/rel8-1.0.0.1/docs/Rel8.html#v:nextval.
Rel8 actually used to have special support for default values, with a special insertion context - but that was removed in 1eaa683. Ultimately we felt that tracking all of this at the type level was just too much. It also put the definition in the Rel8able
, but a Rel8able
can be used with many different tables, not all of which may share the same defaulting, so that was also slightly dubious.
I hope this helps. I'll keep this open as a reminder to add documentation about INSERT
, UPDATE
and DELETE
.
from rel8.
It sure would be nice if the TableSchema
could specify which columns were defaultable, but it doesn't seem particularly dissatisfying to me to use unsafeLiteral "DEFAULT"
and accept the runtime error if I attempt to default something that is not defaultable. I think exporting defaultValue
would be reasonable.
from rel8.
Related Issues (20)
- Failure to build with `opaleye-0.9.3.0` HOT 4
- Rel8 generates poorly-typed sql HOT 4
- Dealing with GENERATED ALWAYS columns? HOT 3
- `rel8-1.3.1.0` does not build with `opaleye-0.9.3.3` HOT 2
- Support for the `ANY` operator? HOT 8
- Documentation should mention that some queries generated by `rel8` have an implicit dependency on postgres versions >= 12
- Anonymous ROW expressions? HOT 1
- Decimal type ? HOT 3
- Rel8 produces invalid SQL: `ERROR: argument of CASE/WHEN must not return a set` HOT 1
- Map Rel8able result to a separate Haskell type? HOT 1
- Return type for `Insert` and `Select`
- `nextval` generates incorrect SQL for sequences with an explicit schema in rel8 1.4.1.0 HOT 7
- logBase generates invalid sql
- `unsafeDefault` generates invalid sql for some queries where it should not HOT 1
- How can EXTRACT be used with this library? HOT 1
- Support ghc-9.6/base-4.18 HOT 1
- Allow hedgehog 1.2 in test suite HOT 4
- rel8 1.4.0.0 does not build with opaleye 0.9.7.0 HOT 2
- Use `ilike` with newtype around `Text`
- How to filter `ListTable`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rel8.