GithubHelp home page GithubHelp logo

Comments (6)

grogancolin avatar grogancolin commented on August 15, 2024 1

Yeah, that is an issue :-/
Making a 1 to 1 mapping between SQL and D is a tricky problem, hence I let people like you do it for me :-)

I was thinking however, of having a @CustomConstraint() UDA, that would be usable like:

struct myStruct{
   @PK @serial id;
   @CustomConstraint("NOT NULL") string email;
}

The constraint would be added with an ALTER TABLE call later (similar to how current constraints are added in your ensureSchema function).

I think that would allow the user to deal with situations like this.
I don't think it'd be overly hard to add either, hopefully I'll get time to experiment with it soon.

Edit: The reason I think a @CustomConstraint may be easier than implementing a @NotNullable is that it's quite obvious to the programmer that what your doing is something custom that isn't handled normally by dpq, and thus you need to take special care here.

from dpq.

IrenejMarc avatar IrenejMarc commented on August 15, 2024 1

I'll look into it in the coming days, thanks for the input. :)

from dpq.

IrenejMarc avatar IrenejMarc commented on August 15, 2024

You're correct, there is currently no way to specify NOT NULL with dpq.

Implementing support for it through @notNullable or similar should not be an issue, but there is however, the issue of what values can actually be nullable according to D. Scalar values cannot be nullable and need to be specified so using the Nullable template, same goes for structs, but not classes or other heap-allocated resources.
Does this mean we should simply assume all D scalar values to be NOT NULL? I'm not sure I want to make such assumptions.

from dpq.

katyukha avatar katyukha commented on August 15, 2024

Also @grogancolin's idea of CustomConstraint may help to deal with other SQL constraints like CHECK (price > 0), etc

from dpq.

grogancolin avatar grogancolin commented on August 15, 2024

Thanks @IrenejMarc !

from dpq.

IrenejMarc avatar IrenejMarc commented on August 15, 2024

v0.8.7 adds support for this https://github.com/IrenejMarc/dpq/releases/tag/v0.8.7

No full constraint support for now, since those would have to operate on a tables themselves, not columns and I can't think of a way to make that look nice right now :)

from dpq.

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.