Skip to content

Commit

Permalink
Update beckn compatible haskell-sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
hemantmangla committed Jul 11, 2022
1 parent 2c9eb73 commit 3abc8fe
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 242 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
*~
dist-newstyle
.dir-locals.el
*.local
dist-local-build/
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,3 @@ Stack:
$ stack build
$ stack test
```
`stack test` doesn't work, because stack does not able to set `lenient` flag for cabal.
Use cabal tests instead.
Be sure the repo has `cabal.project.local` with `packages: ../beam-mysql` inside. Then run `euler dev` and then `cabal test -f lenient`
139 changes: 0 additions & 139 deletions flake.lock

This file was deleted.

76 changes: 76 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: sequelize
version: 1.1.0.0
license: BSD3
author: "Artyom Kazak"
maintainer: "[email protected]"
copyright: "2020 Juspay"

extra-source-files:
- README.md

description: A port of <https://github.com/juspay/purescript-sequelize> into Haskell

default-extensions:
- AllowAmbiguousTypes
- RankNTypes
- ScopedTypeVariables
- StandaloneDeriving
- EmptyDataDecls
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- KindSignatures
- TypeOperators
- MultiParamTypeClasses
- TypeFamilies
- OverloadedLabels
- OverloadedStrings
- DeriveFunctor
- DeriveGeneric
- DataKinds
- DerivingStrategies
- ConstraintKinds
- UndecidableInstances
- InstanceSigs
- BlockArguments
- LambdaCase
- EmptyDataDeriving
- TypeOperators
- ViewPatterns
- KindSignatures

dependencies:
- base >= 4.7 && < 5
- unordered-containers
- vector
- containers
- beam-core
- beam-mysql
- beam-postgres
- beam-sqlite
- generic-lens
- text
- bytestring
- named
- aeson

ghc-options:
- -Wall

library:
source-dirs:
- src

tests:
sequelize-test:
main: Test.hs
source-dirs:
- test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- sequelize
- tasty
- tasty-hunit
20 changes: 10 additions & 10 deletions sequelize.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.0
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.33.0.
--
Expand All @@ -7,7 +7,7 @@ cabal-version: 2.0
-- hash: 492410794b7d56b74a2a0cc2cb2d4ea37d2c1711251fc612e511aab5adfc35e6

name: sequelize
version: 1.1.1.0
version: 1.1.0.0
description: A port of <https://github.com/juspay/purescript-sequelize> into Haskell
author: Artyom Kazak
maintainer: [email protected]
Expand All @@ -30,10 +30,10 @@ library
build-depends:
aeson
, base >=4.7 && <5
, beam-core ^>=0.9.0.0
, beam-mysql ^>=1.3.0.4
, beam-postgres ^>=0.5.0.0
, beam-sqlite ^>=0.5.0.0
, beam-core
, beam-mysql
, beam-postgres
, beam-sqlite
, bytestring
, containers
, generic-lens
Expand All @@ -55,10 +55,10 @@ test-suite sequelize-test
build-depends:
aeson
, base >=4.7 && <5
, beam-core ^>=0.9.0.0
, beam-mysql ^>=1.3.0.4
, beam-postgres ^>=0.5.0.0
, beam-sqlite ^>=0.5.0.0
, beam-core
, beam-mysql
, beam-postgres
, beam-sqlite
, bytestring
, containers
, generic-lens
Expand Down
3 changes: 0 additions & 3 deletions src/Sequelize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ applyWhere mbWhere_ = maybe id (B.filter_' . whereQ) mbWhere_
class ModelMeta table where
modelFieldModification :: table (B.FieldModification (B.TableField table))
modelTableName :: Text
modelSchemaName :: Maybe Text
modelSchemaName = Nothing
mkExprWithDefault :: forall be s.
(B.BeamSqlBackend be, B.Beamable table,
B.FieldsFulfillConstraint (B.BeamSqlBackendCanSerialize be) table) =>
Expand Down Expand Up @@ -389,7 +387,6 @@ modelTableEntity =
let B.EntityModification modification =
B.modifyTableFields (modelFieldModification @table)
<> B.setEntityName (modelTableName @table)
<> B.setEntitySchema (modelSchemaName @table)
in appEndo modification $ B.DatabaseEntity $ B.dbEntityAuto (modelTableName @table)

modelTableEntityDescriptor ::
Expand Down
10 changes: 1 addition & 9 deletions src/Sequelize/Encode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,16 @@ encodeClause dt w =
Is column val -> foldIs column val
foldAnd = \case
[] -> HM.empty
[x] -> foldWhere' x
xs
| Just maps <- mapM fromIs xs -> mconcat maps
| otherwise -> HM.singleton "$and" (Aeson.toJSON $ map foldWhere' xs)
xs -> HM.singleton "$and" (Aeson.toJSON $ map foldWhere' xs)
foldOr = \case
[] -> HM.empty
[x] -> foldWhere' x
xs -> HM.singleton "$or" (Aeson.toJSON $ map foldWhere' xs)
foldIs :: Aeson.ToJSON a => Column table value -> Term be a -> Aeson.Object
foldIs column val =
let key =
B._fieldName . fromColumnar' . column . columnize $
B.dbTableSettings dt
in HM.singleton key $ encodeTerm val
fromIs :: Clause be table -> Maybe Aeson.Object
fromIs = \case
Is column val -> Just (foldIs column val)
_ -> Nothing
in foldWhere' w

-- Warning: the behavior for @Not (Like _)@, @Not (In _)@, @Not (Eq _)@ is
Expand Down
20 changes: 9 additions & 11 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ packages:
- .

extra-deps:
- ../beam/beam-core
- ../beam/beam-migrate
- ../beam/beam-sqlite
- ../beam/beam-postgres
- ../beam-mysql

- named-0.3.0.1@sha256:2975d50c9c5d88095026ffc1303d2d9be52e5f588a8f8bcb7003a04b79f10a06,2312
- git: https://github.com/juspay/beam-mysql
commit: 5d17599e02f30c220b679439ee0c1025e3086250
- git: https://github.com/juspay/beam
commit: f6a35d5361e96c766ae977e9a07fa40c6622808e
subdirs:
- beam-core
- beam-migrate
- beam-sqlite
- beam-postgres
# Needed for beam
- dependent-map-0.4.0.0@sha256:ca2b131046f4340a1c35d138c5a003fe4a5be96b14efc26291ed35fd08c62221,1657
- dependent-sum-0.7.1.0@sha256:5599aa89637db434431b1dd3fa7c34bc3d565ee44f0519bfbc877be1927c2531,2068
Expand All @@ -26,11 +29,6 @@ extra-deps:
- direct-sqlite-2.3.26@sha256:04e835402f1508abca383182023e4e2b9b86297b8533afbd4e57d1a5652e0c23,3718
# Needed for compatibility with euler-hs
- generic-lens-1.1.0.0
- mason-0.2.4@sha256:9de93b2f429fee78f758bd11bea7e183756567bfae4acef369405733bb0538be,1226
- mysql-haskell-0.8.4.3@sha256:d3ca21ae8cc88670f8adb17c7cacb8bb770f1a58d60b5bff346d1f3fc843d98c,3489
- record-dot-preprocessor-0.2.13@sha256:8eb71fdeb5286c71d5c4b0e7768ad14e19a79ae8a102c65c649b64419678332b,2538
- tcp-streams-1.0.1.1@sha256:35e9ecfa515797052f8c3c01834d2daebd5e93f3152c7fc98b32652bf6f0c052,2329
- wire-streams-0.1.1.0@sha256:08816c7fa53b20f52e5c465252c106d9de8e6d9580ec0b6d9f000a34c7bcefc8,2130

extra-include-dirs:
- /usr/local/opt/openssl/include
Expand Down
Loading

0 comments on commit 3abc8fe

Please sign in to comment.