Code Monkey home page Code Monkey logo

squealgen's Introduction

squealgen

Generate squeal types from a running database.

why?

Squeal 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.)
  3. 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 library and recommend it if you're running migrations through Haskell.

hacking?

My workflow looks like this:

DBNAME=somedb make hack

This creates a file src/Schema.hs and then tries to load it. It relies on inotifywait to watch the psql driver (squealgen.sql)

what next?

  • Remove string-hacking, generate in a more principled way.
  • Create a test suite that doesn't rely on a local database, test somewhere else.
  • Extract check constraints (maybe). This is much harder than the rest of it.

squealgen's People

Contributors

mwotton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.