Coder Social home page Coder Social logo

Comments (3)

aspidites avatar aspidites commented on July 17, 2024

Disclaimer: I'm not the author of this library.

While investigating this, I noticed that beam relies on HDBC's SqlColDesc to define HasDefaultFieldSchema instances. HDBC, in turn, relies on mostly ODBC to define SqlTypeIds. A bit of googling suggests that since SQL doesn't typically handle bools, ODBC hasn't either. I know that MySQL represents a bool as a tiny int, so it's not entirely unsurprising.

Whether or not that means this can't be supported is another matter, but I suspect that's why it hasn't been.

from beam.

tathougies avatar tathougies commented on July 17, 2024

Author here. @aspidites is right. Since there's no SqlBoolT, we can't support a backend-neutral boolean type. You could define your own FieldSchema (let's call it boolSchema) that used an integer behind the scenes and then an instance for FromSqlValues for Bool which could correctly marshal between the SQL type and the Haskell type.

For example,

boolSchema :: FieldSchema Bool
boolSchema = FieldSchema {  { fsColDesc = notNull SqlColDesc
                                          { colType = SqlNumericT
                                          , colSize = Nothing
                                          , colOctetLength = Nothing
                                          , colDecDigits = Nothing
                                          , colNullable = Nothing }
                            , fsHumanReadable = "boolSchema"
                            , fsMakeSqlValue = ..
                            , fsFromSqlValue = .. }

instance FromSqlValues Bool -- To get marshalling. Should work automatically

instance Table UserT where
    tblFieldSettings = UserT defFieldSchema
                             defFieldSchema -- Use `defFieldSchema` for all the fields that you want defaulted to the regular type
                             boolSchema -- Since there's no default for Bool types, use boolSchema for the Bool field
                             defFieldSchema
                             ...

If you want to default to the boolean schema you just made for your field, you can define an instance of HasDefaultFieldSchema.

I'm working on improving handling for default fields in the next version. I'm doing this by allowing backends to override more parts of beam's defaults. This will allow backends that support booleans natively to correctly choose a sensible type. Of course, you could always override them using the mechanism described above.

Thanks for reporting the issue, when I get around to implementing support for more than just sqlite (should be soon), I'll include a default boolean type for databases that support it.

from beam.

tathougies avatar tathougies commented on July 17, 2024

Boolean is now supported in back ends that allow it, but not as part of standard sql, which doesn't have a Boolean data type

from beam.

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.