Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mwotton/squealgen
generate haskell types for Squeal from a running postgresql database.
https://github.com/mwotton/squealgen
Last synced: 12 days ago
JSON representation
generate haskell types for Squeal from a running postgresql database.
- Host: GitHub
- URL: https://github.com/mwotton/squealgen
- Owner: mwotton
- License: bsd-3-clause
- Created: 2020-02-03T22:42:24.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-29T13:57:14.000Z (over 3 years ago)
- Last Synced: 2023-04-16T12:07:48.596Z (over 1 year ago)
- Language: Haskell
- Homepage:
- Size: 202 KB
- Stars: 24
- Watchers: 6
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# squealgen
Generate squeal types from a running database.
![CI](https://github.com/mwotton/squealgen/workflows/CI/badge.svg)
## why?
[Squeal](https://hackage.haskell.org/package/squeal-postgresql) is a lovely way to interact with a database, but setting up the initial schema is a struggle.
By default, it assumes you will be managing and migrating your database with Squeal, and if you are starting
from scratch, that works great, but if you're managing it some other way, or even just want to test out Squeal
on an existing database, it's tedious to have to set up the database types and keep them up to date.## how?
1. clone the repo and change into the directory
2. `make prefix=$HOME/.local install`. (We will assume here that `$HOME/.local/bin` is in your path, obviously
feel free to install wherever makes sense to you.)
2. If my database is `cooldb`, my haskell module file is `Schema.hs`, and i want to use the `public` schema (the default),
I would run `squealgen cooldb Schema public > ~/myproject/src/Schema.hs`.You could integrate this in various ways: perhaps just as an initial scaffold, or perhaps integrated as part
of your build process. A true madman could integrate this into a TH call, but I suspect this would be slow and
prone to failing (for instance, better never compile any code if you don't have access to the right version
of psql or a way of spinning up an empty database.)I highly recommend having a scripted way to bring up a temporary database and run all migrations first. I use
Jonathan Fischoff's [tmp-postgres](https://hackage.haskell.org/package/tmp-postgres-1.34.1.0) library and
recommend it if you're running migrations through Haskell.## hacking?
My workflow looks like this:
```make testwatch```
you'll need
- `initdb` from postgresql to be in your PATH. It typically isn't on Ubuntu systems, at least: usually in /usr/lib/postgresql/$VERSION_NUMBER/bin.
- pg_tmp from here: https://eradman.com/ephemeralpg/code/ephemeralpg-3.0.tar.gz
- make
- stack## what next?
- support in-out parameters in functions, once I know how to model this in squeal
- Remove string-hacking, generate in a more principled way.
- Extract check constraints (maybe). This is much harder than the rest of it.
- Triggers