Comments (3)
Yes, that would be nice to have, but it's a bit problematic right now as it requires quite a bit of work.
I don't have enough time to implement it myself, but I can at least describe how I see it, and maybe someone would want to tackle it on their own.
Table
is backend agnostic so I wouldn't mix it with codecs- These type classes are only used for executing queries (functions like
query
,insert
, etc.) and not building queries (whereTable
is concerned - this sort of restricts the number of files that need changes) with the only exception beinglit
(alsolitPG
andlitSQLite3
) - it's already easy to make a version of
lit
that uses codecs instead of type class overloading, the following function is the backbone of bothlitPG
andlitSQLite3
litUnsafeFromForeign ∷ ∀ col s a. Coerce col ⇒ Foreign → col s a
litUnsafeFromForeign = unsafeFromCol <<< Col <<< EForeign
The purpose of codecs or these ad-hoc type classes is to encode/decode records that represent rows in a database.
One record is encoded as Array Foreign
.
The first problem to tackle is to expose low-level, unsafe API in the postgresql-client as the currently exported functions require these ad-hoc type classes anyway.
It would allow us to pass/get Foreign
values to/from pg-client and handle conversion on our own.
For now we could work around that as ToSQLRow
accepts Array Foreign
(it's already utilized to simplify the implementation of insert_
but not insert
nor query
because of the following problem), but the problem is that FromSQLRow
does not have an instance for Array Foreign
so we have to operate on a typed representation which requires more type-level programming.
We need either of the following solutions:
- expose
unsafeQuery
from pg-client - provide an instance of
FromSQLRow (Array Foreign)
, make sure it's enough
The second step would be to implement a generic query
operation that uses codecs
- I'd start by simplifying
genericQueryPG
:purescript-selda/src/Selda/PG/Class.purs
Lines 170 to 183 in e2c56b0
unsafeQuery
in thepgQuery
to return foreigns instead of typed rows thus droppingColsToPGHandler
entirely (look atgenericQuerySQLite3
for inspiration)
In case anyone would want to implement feel free to ask about any details or questions
from purescript-selda.
Rather than export unsafeQuery
directly as is, couldn't there be other versions of the other functions there (e.g. query
) that drop the ToSQLRow
and FromSQLRow
type class constraints?
from purescript-selda.
I think so, yes
from purescript-selda.
Related Issues (20)
- Problem with "pg": "^7.6.0" in package.json
- Question about data intermediate representations HOT 9
- Auto field gets updated HOT 7
- Update returning similar to insert returning
- Easier logging of the update, insert ...
- SELECT values without FROM clause
- Better type inference for insert
- Delete returning
- IS NOT NULL as SQL expression not query needed HOT 4
- `offset` clause missing
- Select Count (*) error HOT 11
- Array distinct unnest ::TEXT[] HOT 3
- good first issues/bugs
- Nested structures/ JSON HOT 2
- Update to be compatible on v0.14.1 PS release HOT 2
- Is there a way to use `insert_` with `ON CONFLICT` HOT 3
- Add primitive queries that don't use type classes
- Update to the new `postgresql-client` API (upcoming v4.0.0)
- Mysql Support HOT 5
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 purescript-selda.