forked from juspay/haskell-sequelize
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2c9eb73
Showing
10 changed files
with
1,239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.stack-work/ | ||
.idea | ||
*.iml | ||
*~ | ||
dist-newstyle | ||
.dir-locals.el | ||
*.local | ||
dist-local-build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# haskell-sequelize | ||
|
||
A port of | ||
[juspay/purescript-sequelize](https://github.com/juspay/purescript-sequelize) | ||
into Haskell, mimicking [Sequelize.js v4](https://sequelize.org/v4). | ||
|
||
## Status | ||
|
||
Has not been tried in production yet. | ||
|
||
Does not provide INSERT or DELETE yet. | ||
|
||
## Usage | ||
|
||
### Table definition | ||
|
||
Define a Beam table: | ||
|
||
```haskell | ||
data TestT f = Test | ||
{ email :: B.Columnar f Text, | ||
enabled :: B.Columnar (B.Nullable f) Bool | ||
} | ||
deriving (Generic) | ||
|
||
type Test = TestT Identity | ||
|
||
instance B.Beamable TestT | ||
|
||
instance B.Table TestT where | ||
data PrimaryKey TestT f = TestId (B.Columnar f Text) deriving (Generic, B.Beamable) | ||
primaryKey = TestId . email | ||
``` | ||
|
||
Define a `ModelMeta` instance. You can modify table properties here. | ||
|
||
```haskell | ||
instance ModelMeta TestT where | ||
modelFieldModification = B.tableModification | ||
modelTableName = "test" | ||
``` | ||
|
||
### SELECT | ||
|
||
Simple SELECT: | ||
|
||
```haskell | ||
{-# LANGUAGE OverloadedLabels #-} | ||
|
||
import Named | ||
|
||
getDisabled :: SqlSelect MySQL Test | ||
getDisabled = | ||
sqlSelect | ||
! #where_ [Is enabled Null] | ||
! defaults | ||
``` | ||
|
||
A more complex SELECT: | ||
|
||
```haskell | ||
{-# LANGUAGE OverloadedLabels #-} | ||
|
||
import Named | ||
|
||
getSpecificPeople :: SqlSelect MySQL Test | ||
getSpecificPeople = | ||
sqlSelect | ||
! #where_ | ||
[ Is enabled (Not Null), | ||
Or [Is email (Eq "[email protected]"), Is email (Eq "[email protected]")] | ||
] | ||
! #orderBy [Asc enabled, Desc email] | ||
! #offset 8 | ||
! #limit 10 | ||
``` | ||
|
||
### UPDATE | ||
|
||
Set some fields: | ||
|
||
```haskell | ||
{-# LANGUAGE OverloadedLabels #-} | ||
|
||
import Named | ||
|
||
busted :: SqlUpdate MySQL TestT | ||
busted = | ||
sqlUpdate | ||
! #set [Set enabled Nothing] | ||
! #where_ [Is enabled (Not Null)] | ||
``` | ||
|
||
Set all fields: | ||
|
||
```haskell | ||
{-# LANGUAGE OverloadedLabels #-} | ||
|
||
import Named | ||
|
||
disableSomeone :: SqlUpdate MySQL TestT | ||
disableSomeone = | ||
sqlUpdate' | ||
! #save (Test "[email protected]" (Just False)) | ||
! #where_ [Is email (Eq "[email protected]")] | ||
``` | ||
|
||
We support `Set` and `SetDefault`. | ||
|
||
## Developing | ||
|
||
Nix: | ||
|
||
```bash | ||
$ nix-shell | ||
|
||
(nix-shell) $ cabal build | ||
(nix-shell) $ cabal test | ||
``` | ||
|
||
Stack: | ||
|
||
```bash | ||
$ 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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: haskell-sequelize | ||
haskell-name: sequelize | ||
allowed-paths: | ||
- sequelize.cabal | ||
- src | ||
- test | ||
|
||
# Disabling tests as they use outdated beam-mysql | ||
disable-tests: true | ||
dependencies: | ||
euler-build: | ||
branch: master | ||
revision: c6af205a7adb1b7abac18f06830f4ed196bfd6e4 | ||
beam: | ||
branch: master | ||
revision: 372542ec6c49d18e8c1c4ef9da15ff0b97c07ed8 | ||
beam-mysql: | ||
branch: master | ||
revision: 1371202ebc3ec7e9ef3e16d1e99f805596022217 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
cabal-version: 2.0 | ||
|
||
-- This file has been generated from package.yaml by hpack version 0.33.0. | ||
-- | ||
-- see: https://github.com/sol/hpack | ||
-- | ||
-- hash: 492410794b7d56b74a2a0cc2cb2d4ea37d2c1711251fc612e511aab5adfc35e6 | ||
|
||
name: sequelize | ||
version: 1.1.1.0 | ||
description: A port of <https://github.com/juspay/purescript-sequelize> into Haskell | ||
author: Artyom Kazak | ||
maintainer: [email protected] | ||
copyright: 2020 Juspay | ||
license: BSD3 | ||
build-type: Simple | ||
extra-source-files: | ||
README.md | ||
|
||
library | ||
exposed-modules: | ||
Sequelize | ||
Sequelize.Encode | ||
other-modules: | ||
Paths_sequelize | ||
hs-source-dirs: | ||
src | ||
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 | ||
ghc-options: -Wall | ||
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 | ||
, bytestring | ||
, containers | ||
, generic-lens | ||
, named | ||
, text | ||
, unordered-containers | ||
, vector | ||
default-language: Haskell2010 | ||
|
||
test-suite sequelize-test | ||
type: exitcode-stdio-1.0 | ||
main-is: Test.hs | ||
other-modules: | ||
Paths_sequelize | ||
hs-source-dirs: | ||
test | ||
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 | ||
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N | ||
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 | ||
, bytestring | ||
, containers | ||
, generic-lens | ||
, named | ||
, sequelize | ||
, tasty | ||
, tasty-hunit | ||
, text | ||
, unordered-containers | ||
, vector | ||
default-language: Haskell2010 |
Oops, something went wrong.