holistics / holistics/dbml

Add support for Postgres Functions

Open
#829 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.7k
Forks
233
Avg merge
1d 23h
Merged PRs (30d)
4

Description

### Enhancement

Add support to generate `CREATE OR REPLACE FUNCTION` sql scripts using dbml markdown.

### Syntax

```
Function increment {
schema public
returns integer
args [len_from: integer, len_from: integer]
body `
DECLARE
film_count INTEGER;
BEGIN
SELECT COUNT(*)
INTO film_count
FROM film
WHERE length BETWEEN len_from AND len_to;
RETURN film_count;
END;
`
language plpgsql
behavior volatile
security invoker
}
```

`schema` defaults to public. Can be specified inline with the function name such as `Function public.increment { ... }`
`returns` accepts any valid return type (see list below).
`args` accepts a list of arguments with declared types. Any return type is valid, excluding `void`, `record`, and `trigger`.
`body` accepts an expression or a multi-line expression.
`language` defaults to `plpgsql`. Can be `sql`, `c`, or `internal`.
`behavior` defaults to `volatile`. Can be `immutable` or `stable`.
`security` defaults to `invoker`. Can be `definer`.

Return types:

- `void`
- `record`
- `trigger`
- `integer`
- `bool`
- `bytea`
- `date`
- `double_precision`
- `float4`
- `float8`
- `int2`
- `int4`
- `int8`
- `json`
- `jsonb`
- `numeric`
- `text`
- `time`
- `timestamp`
- `timestamptz`
- `timetz`
- `uuid`
- `varchar`
- `vector`

### Gaps

Does not implement configuration parameters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.