-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable value-level codecs #61
Changes from 22 commits
090a5a4
64507b8
c823b72
72c24b4
c6a3ac7
45cc056
c5a1b54
95c97af
60691d5
c1cbe9d
e439409
31e384f
ec46ca3
83bfc53
dfab960
ed3b14b
3e18ca7
35d104b
59614c0
027377c
f20eb2e
1b242de
aff12e3
4eae180
6943a25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,5 @@ You can edit this file as you like. | |
, "variant" | ||
] | ||
, packages = ./packages.dhall | ||
, sources = [ "src/**/*.purs", "test/**/*.purs", "guide/src/**/*.purs" ] | ||
, sources = [ "src/**/*.purs" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be reverted before a final PR is merged. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
module Selda.PG.Aff | ||
( insert_ | ||
, insert | ||
, insert1 | ||
, insert_' | ||
-- , insert | ||
-- , insert1 | ||
, insert1_ | ||
, insert1_' | ||
, query | ||
, query' | ||
, query1 | ||
, query1' | ||
, PGSelda | ||
, deleteFrom | ||
, update | ||
|
@@ -17,16 +21,20 @@ import Control.Monad.Reader (ReaderT) | |
import Data.Array (head) as Array | ||
import Data.Either (Either) | ||
import Data.Maybe (Maybe) | ||
import Database.PostgreSQL (class FromSQLRow, Connection, PGError) | ||
import Database.PostgreSQL (class FromSQLRow, class ToSQLRow, Connection, PGError, fromSQLRow) | ||
import Effect.Aff (Aff) | ||
import Foreign (Foreign) | ||
import Heterogeneous.Folding (class HFoldl) | ||
import Selda (Col, Table) | ||
import Selda.Col (class GetCols) | ||
import Selda.PG.Class (class InsertRecordIntoTableReturning, BackendPGClass) | ||
import Selda.PG.Class as Selda.PG | ||
import Selda.Query (limit) | ||
import Selda.Query.Class (class GenericInsert, runSelda) | ||
import Selda.Query.Type (FullQuery(..)) | ||
import Selda.Query.Utils (class ColsToPGHandler, class TableToColsWithoutAlias) | ||
import Selda.Query.Utils (class ColsToPGHandler, class TableToColsWithoutAlias, RecordToArrayForeign, RecordToTuple(..)) | ||
import Selda.Table.Constraint (class CanInsertColumnsIntoTable) | ||
import Type.Proxy (Proxy(..)) | ||
|
||
type PGSelda = ExceptT PGError (ReaderT Connection Aff) | ||
|
||
|
@@ -35,34 +43,90 @@ type B = BackendPGClass | |
insert_ | ||
∷ ∀ t r | ||
. GenericInsert BackendPGClass PGSelda t r | ||
⇒ HFoldl | ||
(RecordToArrayForeign BackendPGClass) | ||
(Array Foreign) | ||
{ | r } | ||
(Array Foreign) | ||
⇒ Connection → Table t → Array { | r } → Aff (Either PGError Unit) | ||
insert_ conn t r = runSelda conn $ Selda.PG.insert_ t r | ||
insert_ conn t r = | ||
runSelda conn $ Selda.PG.insert_ t r | ||
|
||
insert_' | ||
∷ ∀ t r | ||
. GenericInsert BackendPGClass PGSelda t r | ||
⇒ Connection | ||
→ Table t | ||
→ ({ | r } → Array Foreign) | ||
→ Array { | r } | ||
→ Aff (Either PGError Unit) | ||
insert_' conn t decodeRow r = | ||
runSelda conn $ Selda.PG.insert_' t decodeRow r | ||
|
||
insert1_ | ||
∷ ∀ r t | ||
. GenericInsert BackendPGClass PGSelda t r | ||
⇒ Connection → Table t → { | r } → Aff (Either PGError Unit) | ||
⇒ HFoldl | ||
(RecordToArrayForeign BackendPGClass) | ||
(Array Foreign) | ||
{ | r } | ||
(Array Foreign) | ||
⇒ Connection | ||
→ Table t | ||
→ { | r } | ||
→ Aff (Either PGError Unit) | ||
insert1_ conn t r = runSelda conn $ Selda.PG.insert1_ t r | ||
|
||
insert | ||
∷ ∀ r t tr | ||
. InsertRecordIntoTableReturning r t tr | ||
⇒ Connection → Table t → Array { | r } → Aff (Either PGError (Array { | tr })) | ||
insert conn t r = runSelda conn $ Selda.PG.insert t r | ||
insert1_' | ||
∷ ∀ r t | ||
. GenericInsert BackendPGClass PGSelda t r | ||
⇒ Connection | ||
→ Table t | ||
→ ({ | r } → Array Foreign) | ||
→ { | r } | ||
→ Aff (Either PGError Unit) | ||
insert1_' conn t encode r = runSelda conn $ Selda.PG.insert1_' t encode r | ||
|
||
-- insert | ||
-- ∷ ∀ r t ret rTuple tr trTuple s | ||
-- . InsertRecordIntoTableReturning r t ret | ||
-- ⇒ ToSQLRow rTuple | ||
-- ⇒ FromSQLRow trTuple | ||
-- ⇒ HFoldl RecordToTuple Unit { | r } rTuple | ||
-- ⇒ ColsToPGHandler s tr trTuple ret | ||
-- ⇒ TableToColsWithoutAlias s t tr | ||
-- ⇒ Connection → Table t → Array { | r } → Aff (Either PGError (Array { | ret })) | ||
-- insert conn t r = runSelda conn $ Selda.PG.insert t r | ||
|
||
insert1 | ||
∷ ∀ r t tr | ||
. InsertRecordIntoTableReturning r t tr | ||
⇒ Connection → Table t → { | r } → Aff (Either PGError { | tr }) | ||
insert1 conn t r = runSelda conn $ Selda.PG.insert1 t r | ||
-- insert1 | ||
-- ∷ ∀ r t ret rTuple tr trTuple s | ||
-- . InsertRecordIntoTableReturning r t ret | ||
-- ⇒ ToSQLRow rTuple | ||
-- ⇒ FromSQLRow trTuple | ||
-- ⇒ HFoldl RecordToTuple Unit { | r } rTuple | ||
-- ⇒ ColsToPGHandler s tr trTuple ret | ||
-- ⇒ TableToColsWithoutAlias s t tr | ||
-- ⇒ Connection → Table t → { | r } → Aff (Either PGError { | ret }) | ||
-- insert1 conn t r = runSelda conn $ Selda.PG.insert1 t r | ||
|
||
query | ||
∷ ∀ o i tup | ||
. ColsToPGHandler B i tup o | ||
⇒ GetCols i | ||
⇒ FromSQLRow tup | ||
⇒ Connection → FullQuery B (Record i) → Aff (Either PGError (Array { | o })) | ||
query conn q = runSelda conn $ Selda.PG.query q | ||
⇒ Connection | ||
→ FullQuery B (Record i) | ||
→ Aff (Either PGError (Array { | o })) | ||
query conn = runSelda conn <<< Selda.PG.query | ||
|
||
query' | ||
∷ ∀ o i | ||
. GetCols i | ||
⇒ Connection | ||
→ FullQuery B { | i } | ||
→ (Array Foreign -> Either String { | o }) | ||
→ Aff (Either PGError (Array { | o })) | ||
query' conn q decodeRow = runSelda conn $ Selda.PG.query' q decodeRow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eta-reducing these produces compiler errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean? there's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I was thinking |
||
|
||
query1 | ||
∷ ∀ o i tup | ||
|
@@ -72,7 +136,18 @@ query1 | |
⇒ Connection | ||
→ FullQuery B (Record i) | ||
→ Aff (Either PGError (Maybe { | o })) | ||
query1 conn (FullQuery q) = query conn (FullQuery (limit 1 >>= \_ → q)) <#> map Array.head | ||
query1 conn (FullQuery q) = | ||
query conn (FullQuery (limit 1 >>= \_ → q)) <#> map Array.head | ||
|
||
query1' | ||
∷ ∀ o i | ||
. GetCols i | ||
⇒ Connection | ||
→ FullQuery B (Record i) | ||
→ (Array Foreign -> Either String { | o }) | ||
→ Aff (Either PGError (Maybe { | o })) | ||
query1' conn (FullQuery q) decodeRow = | ||
query' conn (FullQuery (limit 1 >>= \_ → q)) decodeRow <#> map Array.head | ||
|
||
deleteFrom | ||
∷ ∀ r r' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using my fork temporarily.