diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-04-27 13:00:30 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-27 13:00:30 -0300 |
| commit | 56492ad5f6f09d8c9f337d42803b64d1b9f0668b (patch) | |
| tree | 0a41825d319fe47e037e2e30ed515c3c2d9b0d7d /lib/qualified_name.ml | |
| parent | 12f170f438f5909511da2f26c5d33a85acc1fe64 (diff) | |
| download | Sakura-56492ad5f6f09d8c9f337d42803b64d1b9f0668b.tar.gz Sakura-56492ad5f6f09d8c9f337d42803b64d1b9f0668b.zip | |
Introduce Multigroups (#65)
Diffstat (limited to 'lib/qualified_name.ml')
| -rw-r--r-- | lib/qualified_name.ml | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/qualified_name.ml b/lib/qualified_name.ml new file mode 100644 index 0000000..b6d01bb --- /dev/null +++ b/lib/qualified_name.ml @@ -0,0 +1,31 @@ +(** Fully qualified relation name: [multigroup:schema:relation]. + + Splits on [:], fills defaults for missing parts. + - ["relation"] -> { multigroup=""; schema="public"; relation } + - ["schema:relation"] -> { multigroup=""; schema; relation } + - ["mg:schema:relation"] -> { multigroup=mg; schema; relation } +*) + +type t = { + multigroup : string; + schema : string; + relation : string; +} + +let default_schema = "public" + +let parse s = + match String.split_on_char ':' s with + | [ rel ] -> { multigroup = ""; schema = default_schema; relation = rel } + | [ schema; rel ] -> { multigroup = ""; schema; relation = rel } + | [ mg; schema; rel ] -> { multigroup = mg; schema; relation = rel } + | _ -> { multigroup = ""; schema = default_schema; relation = s } + +let make ?(multigroup = "") ?(schema = default_schema) relation = + { multigroup; schema; relation } + +let to_string { multigroup; schema; relation } = + if multigroup = "" then schema ^ ":" ^ relation + else multigroup ^ ":" ^ schema ^ ":" ^ relation + +let to_key { schema; relation; _ } = schema ^ ":" ^ relation |
