gagandeepb / frames-beam Goto Github PK
View Code? Open in Web Editor NEWAccessing Postgres in a data frame in Haskell
License: BSD 3-Clause "New" or "Revised" License
Accessing Postgres in a data frame in Haskell
License: BSD 3-Clause "New" or "Revised" License
/home/travis/build/gagandeepb/Frames-beam/src/UsageExample.hs:36:1: error:
Could not find module ‘Schema’
Use -v to see a list of the files searched for.
|
36 | import Schema
| ^^^^^^^^^^^^^^^^^^^^^^^
Using Control.Exception.bracket
Unit tests
DB integration tests on Travis
upon building my project:
• Couldn't match kind ‘*’
with ‘(ghc-prim-0.5.1.1:GHC.Types.Symbol, *)’
When matching the kind of ‘ZipTypes b_names b_rs’
Expected type: b Identity
-> Frames.Rec.Record (ZipTypes b_names b_rs)
Actual type: b Identity
-> Data.Vinyl.Core.Rec
Data.Vinyl.Functor.Identity (ZipTypes b_names b_rs)
• In the first argument of ‘map’, namely ‘createRecId’
In the expression: map createRecId bQRes
In an equation for ‘bRecs’: bRecs = map createRecId bQRes
• Relevant bindings include
bRecs :: [Frames.Rec.Record (ZipTypes b_names b_rs)]
(bound at src/Frames/SQL/Beam/Postgres/Query.hs:66:5)
join2 :: JoinQueryResults a b
-> FrameRec (ZipTypes a_names a_rs ++ ZipTypes b_names b_rs)
(bound at src/Frames/SQL/Beam/Postgres/Query.hs:61:1)
using this stack.yaml
resolver: lts-11.7
packages:
- .
extra-deps:
- Frames-0.5.0
- beam-core-0.7.2.2
- beam-migrate-0.3.2.1
- beam-postgres-0.3.2.2
- vinyl-0.10.0
- Frames-beam-0.1.0.1
The idea: A call to genBeamSchema
currently creates a new file named NewBeamSchema.hs
in the src
directory (relative to project root) with generated code corresponding to the database schema in it. This module then needs to get imported in the calling module in order to be used further.
It has been suggested that the generated code should come into scope in the calling module directly, and not go into a separate module of it's own. The primary difficulties in being able to do so are the following:
The generated code is a full Haskell module in String
form. In order to splice it into the calling module would require a transformation from String
to some sort of Intermediate Representation (IR)
and from the IR
to TemplateHaskell's [Dec]
. The only way I know of doing this via the haskell-src-meta
library. Initial attempts to use this approach have failed (I got a partially parsed output with a "Parse Error" when I last tried), but it is possible that I'm doing something wrong.
The second difficulty has more to do with the user experience of the library. Assuming we succeed in the above attempts at splicing the generated code into the calling module; the user would then need to pass in compiler flags to inspect the generated code in order to know what declarations to pass onwards to deriveGeneric
and deriveVinyl
. This could possibly be an inconvenience to some users.
Having said the above, any help/feedback with regards to this issue will be appreciated.
cc @ocramz
With
let
myHaskellPackageOverlay = self: super: {
myHaskellPackages = super.haskellPackages.override {
overrides = hself: hsuper: rec {
htoml = super.haskell.lib.dontCheck (hself.callCabal2nixWithOptions "htoml" (builtins.fetchGit {
url = "https://github.com/mirokuratczyk/htoml";
rev = "33971287445c5e2531d9605a287486dfc3cbe1da";
}) "" { });
hasql-streams-core = super.haskell.lib.doJailbreak hsuper.hasql-streams-core;
hasql-streams-conduit = super.haskell.lib.doJailbreak hsuper.hasql-streams-conduit;
hasql-transaction-io = super.haskell.lib.doJailbreak hsuper.hasql-transaction-io;
hasql-streams-pipes = super.haskell.lib.doJailbreak hsuper.hasql-streams-pipes;
hasql-streams-streaming = super.haskell.lib.doJailbreak hsuper.hasql-streams-streaming;
hasql-streams-streamly = super.haskell.lib.doJailbreak hsuper.hasql-streams-streamly;
};
};
};
in
{ nixpkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixpkgs-22.05-darwin.tar.gz")
{
overlays = [ myHaskellPackageOverlay ];
config.allowBroken = true;
}
}:
let
pkgs = nixpkgs;
haskellDeps = ps: with ps; [
base
beam-core
beam-migrate
beam-postgres
text
Frames
template-haskell
generics-sop
vinyl
process
conduit
monad-control
bytestring
scientific
time
uuid-types
hspec
hspec-core
QuickCheck
];
in
pkgs.stdenv.mkDerivation {
name = "rOnly";
buildInputs = [
pkgs.libintlOrEmpty
pkgs.stack
(pkgs.myHaskellPackages.ghcWithPackages haskellDeps)
pkgs.darwin.apple_sdk.frameworks.Cocoa
];
}
I get
[nix-shell:~/Frames-beam]$ stack build
stack build
No setup information found for ghc-8.2.2 on your platform.
This probably means a GHC bindist has not yet been added for OS key 'macosx-aarch64'.
Supported versions: ghc-8.10.5, ghc-8.10.6, ghc-8.10.7, ghc-9.0.2, ghc-9.2.1, ghc-9.2.2, ghc-9.2.3, ghc-9.2.4, ghc-9.2.5, ghc-9.2.6, ghc-9.2.7, ghc-9.2.8, ghc-9.4.1, ghc-9.4.2, ghc-9.4.3, ghc-9.4.4, ghc-9.4.5, ghc-9.6.1, ghc-9.6.2
and
[nix-shell:~/Frames-beam]$ cabal build
cabal build
Build profile: -w ghc-9.0.2 -O1
In order, the following will be built (use -v for more details):
- Frames-beam-0.2.0.0 (lib) (first run)
Preprocessing library for Frames-beam-0.2.0.0..
Building library for Frames-beam-0.2.0.0..
[4 of 6] Compiling Frames.SQL.Beam.Postgres.Query ( src/Frames/SQL/Beam/Postgres/Query.hs, /Users/dom/Frames-beam/dist-newstyle/build/aarch64-osx/ghc-9.0.2/Frames-beam-0.2.0.0/build/Frames/SQL/Beam/Postgres/Query.o, /Users/dom/Frames-beam/dist-newstyle/build/aarch64-osx/ghc-9.0.2/Frames-beam-0.2.0.0/build/Frames/SQL/Beam/Postgres/Query.dyn_o )
src/Frames/SQL/Beam/Postgres/Query.hs:38:18: error:
• Couldn't match type ‘Postgres’ with ‘PgSelectSyntax’
Expected: Q PgSelectSyntax b s (a (QExpr PgExpressionSyntax s))
Actual: Q Postgres b s (a (QExpr Postgres s))
• In the expression: all_ (tbl db)
In an equation for ‘allRows’: allRows tbl db = all_ (tbl db)
|
38 | allRows tbl db = all_ (tbl db)
| ^^^^^^^^^^^^^
src/Frames/SQL/Beam/Postgres/Query.hs:52:3: error:
• Couldn't match type ‘PgExpressionSyntax’ with ‘PgSelectSyntax’
Expected: Q PgSelectSyntax b s (a (QExpr PgExpressionSyntax s))
Actual: Q PgExpressionSyntax b s (a (QExpr PgExpressionSyntax s))
• In the expression: filter_ (filterLambda) (allRows tbl db)
In an equation for ‘allRowsWhere’:
allRowsWhere tbl db filterLambda
= filter_ (filterLambda) (allRows tbl db)
|
52 | filter_ (filterLambda) (allRows tbl db)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/Frames/SQL/Beam/Postgres/Query.hs:52:27: error:
• Couldn't match type ‘PgSelectSyntax’ with ‘PgExpressionSyntax’
Expected: Q PgExpressionSyntax b s (a (QExpr PgExpressionSyntax s))
Actual: Q PgSelectSyntax b s (a (QExpr PgExpressionSyntax s))
• In the second argument of ‘filter_’, namely ‘(allRows tbl db)’
In the expression: filter_ (filterLambda) (allRows tbl db)
In an equation for ‘allRowsWhere’:
allRowsWhere tbl db filterLambda
= filter_ (filterLambda) (allRows tbl db)
|
52 | filter_ (filterLambda) (allRows tbl db)
| ^^^^^^^^^^^^^^
Without the jail breaks, the dependencies do not compile.
[nix-shell:~/Frames-beam]$ stack build
stack build
No setup information found for ghc-8.2.2 on your platform.
This probably means a GHC bindist has not yet been added for OS key 'macosx-aarch64'.
Supported versions: ghc-8.10.5, ghc-8.10.6, ghc-8.10.7, ghc-9.0.2, ghc-9.2.1, ghc-9.2.2, ghc-9.2.3, ghc-9.2.4, ghc-9.2.5, ghc-9.2.6, ghc-9.2.7, ghc-9.2.8, ghc-9.4.1, ghc-9.4.2, ghc-9.4.3, ghc-9.4.4, ghc-9.4.5, ghc-9.6.1, ghc-9.6.2
[nix-shell:~/Frames-beam]$ cabal build
cabal build
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: Frames-beam-0.2.0.0 (user goal)
[__1] next goal: vinyl (dependency of Frames-beam)
[__1] rejecting: vinyl-0.14.3 (conflict: Frames-beam => vinyl>=0.10 && <0.11)
[__1] skipping: vinyl-0.14.2, vinyl-0.14.1, vinyl-0.13.3, vinyl-0.13.2,
vinyl-0.13.1, vinyl-0.13.0, vinyl-0.12.3, vinyl-0.12.1, vinyl-0.12.0,
vinyl-0.11.0 (has the same characteristics that caused the previous version to
fail: excluded by constraint '>=0.10 && <0.11' from 'Frames-beam')
[__1] trying: vinyl-0.10.0.1
[__2] next goal: base (dependency of Frames-beam)
[__2] rejecting: base-4.16.4.0/installed-4.16.4.0 (conflict: vinyl =>
base>=4.7 && <4.13)
[__2] skipping: base-4.18.0.0, base-4.17.1.0, base-4.17.0.0, base-4.16.4.0,
base-4.16.3.0, base-4.16.2.0, base-4.16.1.0, base-4.16.0.0, base-4.15.1.0,
base-4.15.0.0, base-4.14.3.0, base-4.14.2.0, base-4.14.1.0, base-4.14.0.0,
base-4.13.0.0 (has the same characteristics that caused the previous version
to fail: excluded by constraint '>=4.7 && <4.13' from 'vinyl')
[__2] rejecting: base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__2] fail (backjumping, conflict set: Frames-beam, base, vinyl)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: Frames-beam, vinyl, base
Hi Gagandeep!
I was looking at your work, good stuff! In order to study/experiment with it I was able to update it to lts-14.1; would you be interested if I submitted the changes I have as a PR? Might help other learners like me who want to look at it.
Best,
Jorge
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.