sqldelight / sqldelight/sql-psi
Support create type statement in core grammer
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 104
- Forks
- 35
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 14
Description
In PostgreSql, CREATE TYPE is used for Enums, Ranges and Composite types. https://www.postgresql.org/docs/15/sql-createtype.html
The ALTER TYPE statement would also have to be added.
Based on the feature request https://github.com/cashapp/sqldelight/issues/4339, I created a minimum attempt to
implement CREATE TYPE ... AS ENUM.
I tried this with a local snapshot -> https://github.com/AlecStrong/sql-psi/compare/master...griffio:sql-psi:create-type and https://github.com/cashapp/sqldelight/compare/master...griffio:sqldelight:add-postgres-enum-type
Initially, I tried using the extension_stmt in the core sql.bnf but it needs have it's own statement to avoid ambiguity.
Currently, the sql-delight database generator outputs create table schema elements first, create type needs to be before these and have a dedicated type that can be selected in TreeUtil.
Examples of known schema creation statements in SQL dialects
CREATE DATABASE (Non standard variably supported)
CREATE DOMAIN (Non standard supported by Postgres)
CREATE INDEX (Non standard and supported)
CREATE SCHEMA (Standard variably supported)
CREATE SEQUENCE (Standard but extended by Postgres)
CREATE TABLE (Standard and supported)
CREATE TYPE (Non standard but supported by Postgres)
CREATE VIEW (Standard and supported)
This is also the same for ALTER and DROP statements - I believe that the core grammar should have these place-holder statements that can be overridden by Dialects
🥫 It maybe that this feature can be deferred till after 2.0 is released and more breaking changes could be supported
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the core sql.bnf grammar and the schema-element handling in sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/lang/util/TreeUtil.kt. Review the linked sql-psi and sqldelight comparison branches, then determine the required core placeholders and dialect behavior for CREATE TYPE and the related ALTER and DROP statements. Done means PostgreSQL CREATE TYPE forms can be parsed and selected in the correct schema order without ambiguity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, postgresql, sql
- Domain
- compilers, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100