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 functionsConvenience builders for Rails-style naming — table_case, foreign-key generation, ClassCase, module-path conversion, and (DuckDB 2.0 build) human-readable labels, URL slugs and table-to-class names.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
table_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Turn a table name into a class name, like Rails classify: the last word is singularized and the result is rendered in PascalCase. Respects the inflector_acronyms setting. New in the DuckDB 2.0 build.
SELECT inflector_classify('egg_and_hams') AS a, inflector_classify('people') AS b;
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
text
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Turn an identifier into a human-readable label, like Rails humanize: a trailing _id is dropped and the rest is rendered in Sentence case. Respects the inflector_acronyms setting. New in the DuckDB 2.0 build.
SELECT inflector_humanize('author_id') AS a, inflector_humanize('employee_salary') AS b;
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
text
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Build a URL slug: accents are removed, letters are lowercased, and every run of characters that are not letters or digits becomes a single -, with no leading or trailing dash. Letters and digits from other scripts (for example CJK) are kept. New in the DuckDB 2.0 build.
SELECT inflector_parameterize('Crème Brûlée: A Recipe!');
Related functions
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
text
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Rails-style 'table_case' — snake_case + plural. e.g. UserAccount → user_accounts.
SELECT inflector_to_table_case('FooBar');
Output
| inflector_to_table_case('FooBar') |
|---|
| foo_bars |