Coder Social home page Coder Social logo

Comments (2)

ocharles avatar ocharles commented on August 18, 2024

A great question! We certainly need to document this, but here are a few solutions at the moment:

  1. Use unsafeLiteral "DEFAULT", as you mentioned. We haven't exported this as a definition (e.g., defaultValue = unsafeLiteral "DEFAULT") due to its, well, unsafeness.
  2. 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.

chris-martin avatar chris-martin commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.