Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paurkedal/episql
SQL schema parser and code generator
https://github.com/paurkedal/episql
code-generator ocaml sql sql-schema-parser
Last synced: 3 days ago
JSON representation
SQL schema parser and code generator
- Host: GitHub
- URL: https://github.com/paurkedal/episql
- Owner: paurkedal
- License: lgpl-3.0
- Created: 2014-08-23T17:57:21.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T16:23:45.000Z (11 months ago)
- Last Synced: 2023-12-18T20:08:47.387Z (11 months ago)
- Topics: code-generator, ocaml, sql, sql-schema-parser
- Language: OCaml
- Homepage:
- Size: 482 KB
- Stars: 28
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: COPYING
Awesome Lists containing this project
README
# epiSQL - SQL schema parser and code generator
## Synopsis
epiSQL /ˈɛpɪˈsiːkwəl/ is an SQL schema parser and code generator. It
supports a subset of SQL `CREATE`-statements with focus on PostgreSQL. It
contains generators for* [Caqti][], providing a persistence-style API with caching,
* XML, providing easy access for external applications to the schema, and
* Unix shells, providing a series of function calls for general ad-hoc use.## Caqti Persistence
**Note**: This generator will likely be replaced with one providing an
incompatible API, so don't use it for new projects.This backend maps database rows to memory-cached objects, and provides an
interface to fetch, insert, update, and delete individual objects. It is
assumed that only one application access the cached tables.Cache-coherent search functions limited to single-table queries are
provided, as well.Definitions are only generated for tables which explicitly specifies a
primary key. The primary key is used to address objects.It is recommended to generate four separate files, e.g.
``` sh
episql -g caqti-persist-types-mli -o foo_types.mli foo.sql
episql -g caqti-persist-types-ml -o foo_types.ml foo.sql
episql -g caqti-persist-mli -t Foo_types -o foo_functor.mli foo.sql
episql -g caqti-persist-ml -t Foo_types -o foo_functor.ml foo.sql
```The `Foo_types` module will contain pure types and related functions, which
supports deriving annotations (see `-deriving`). The `Foo_functor` module
contains a functor which can be instantiated with caching and database
traits. For more details see``` sh
episql -g caqti-persist-ml -help
```## XML Output
The switch `-g xml` produces an XML dump of the database schema, making it
possible for external software to extract information from the schema
without parsing SQL. E.g. this could be used to implement an alternative
code generator using an XSLT.The above example translates to
``` xml
```
## Shell Output
Use `-g shell` to create a sequence of command invocations corresponding to
the table definitions. E.g. the above example produce``` sh
enter_create_table testarea.note
add_column testarea.note note_id 'serial' "PRIMARY KEY"
add_column testarea.note note 'text' "NOT NULL"
leave_create_table testarea.note
```This is not meant as a permanent solution, but provides a quick way to
inspect or generate unsupported code. The XML generator described above
provides a more faithful representation and is more appropriate for external
applications.[Caqti]: https://github.com/paurkedal/ocaml-caqti
[Macaque]: http://ocsigen.org/macaque/