Skip to content

Naming Helpers functions in the Inflector DuckDB extension

Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for inflector cookbook / technical-details / functions.json examples.
-- Small, deterministic, idempotent. Backs snippets that read from
-- `api_events` (struct payload), `models` (class names), `mixed_input`
-- (raw case-mixed strings), and `left_records` / `right_records` (dedupe pair).

CREATE OR REPLACE TABLE api_events (
    id       INTEGER,
    payload  STRUCT(firstName TEXT, lastName TEXT)
);
INSERT INTO api_events VALUES
    (1, {'firstName': 'John',  'lastName': 'Doe'}),
    (2, {'firstName': 'Jane',  'lastName': 'Roe'}),
    (3, {'firstName': 'Mary',  'lastName': 'Sue'});

CREATE OR REPLACE TABLE models (
    class_name  TEXT
);
INSERT INTO models VALUES
    ('UserAccount'),
    ('Message'),
    ('Order');

CREATE OR REPLACE TABLE mixed_input (
    raw  TEXT
);
INSERT INTO mixed_input VALUES
    ('helloWorld'),
    ('HelloWorld'),
    ('hello_world'),
    ('hello-world');

CREATE OR REPLACE TABLE left_records (
    id    INTEGER,
    name  TEXT
);
INSERT INTO left_records VALUES
    (1, 'helloWorld'),
    (2, 'fooBar');

CREATE OR REPLACE TABLE right_records (
    id    INTEGER,
    name  TEXT
);
INSERT INTO right_records VALUES
    (10, 'hello_world'),
    (20, 'foo_bar');

-- Small files for the file-ingestion examples, in the browser's filesystem.
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName, '[email protected]' AS emailAddress)
TO 'users.csv' (HEADER true);
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName)
TO 'data.csv' (HEADER true);
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName)
TO 'events.json' (FORMAT JSON, ARRAY true);

Function category

Naming Helpers

4 functions

inflector_classify

Scalar function Naming Helpers
Signature
inflector_classify(table_name: VARCHAR) → VARCHAR
Arguments (Positional)
Argument table_name Type VARCHAR Mode Positional Description
Description
1 Table names to class names
SELECT inflector_classify('egg_and_hams') AS a, inflector_classify('people') AS b;

inflector_humanize

Scalar function Naming Helpers
Signature
inflector_humanize(text: VARCHAR) → VARCHAR
Arguments (Positional)
Argument text Type VARCHAR Mode Positional Description
Description
1 Column names to labels
SELECT inflector_humanize('author_id') AS a, inflector_humanize('employee_salary') AS b;

inflector_parameterize

Scalar function Naming Helpers
Signature
inflector_parameterize(text: VARCHAR) → VARCHAR
Arguments (Positional)
Argument text Type VARCHAR Mode Positional Description
Description
1 Title to slug
SELECT inflector_parameterize('Crème Brûlée: A Recipe!');

inflector_to_table_case

Scalar function Naming Helpers
Signature
inflector_to_table_case(text: VARCHAR) → VARCHAR
Arguments (Positional)
Argument text Type VARCHAR Mode Positional Description
Description
1 Example 1
SELECT inflector_to_table_case('FooBar');

Output

inflector_to_table_case('FooBar')
foo_bars