Comments (3)
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.
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.
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)
- A variant of select that doesn't require QBaseScope HOT 2
- Faster pull request workflow. HOT 5
- Unnecessary subquery layers in unionAll_ for Postgres HOT 1
- LensFor: `Couldn't match expected type p` HOT 7
- Requesting `subselectWith_` combinator HOT 1
- beam-postgres: runBeamPostgres is so hard to find in doc
- Lens example in tutorial does not work HOT 1
- GHC 9.6 failures HOT 3
- beam-sqlite: No `instance HasSqlEqualityCheck Sqlite Day` HOT 1
- WHERE clauses are silently dropped if there is no FROM HOT 1
- beam-sqlite: support for `LIKE` + `ESCAPE` ? HOT 1
- free-5.2 not allowed
- vector-0.13 not allowed
- primitive-0.8 not allowed HOT 3
- How to get primary key type? HOT 1
- Subquery without aggregation
- Multicolumn aggregate HOT 1
- Is there any way to reuse a `ToField`, `FromField` definitions from sqlite-simple? HOT 1
- Precise type for `max_` aggregate function
- Postgres column doesn't roundtrip for type `Maybe (Vector Text)`
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 beam.