Skip to content

Commit 96bb5b8

Browse files
committed
fix: docs
1 parent 20e1b44 commit 96bb5b8

File tree

2 files changed

+206
-11
lines changed

2 files changed

+206
-11
lines changed

docs/README.md

Lines changed: 205 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# DuckDB Inflector Extension by [Query.Farm](https://query.farm)
22

3-
The **Inflector** extension, developed by **[Query.Farm](https://query.farm)**, brings string case transformation and inflection capabilities directly to your SQL queries in DuckDB. Effortlessly convert, check, and manipulate string case styles, pluralization, and more—right inside your database.
3+
The **Inflector** extension, developed by **[Query.Farm](https://query.farm)**, brings powerful string case transformation and inflection capabilities directly to your SQL queries in DuckDB. Transform column names, validate naming conventions, handle pluralization, and more—all without leaving your database environment.
4+
5+
Whether you're normalizing API responses, migrating schemas between naming conventions, or ensuring consistent data formatting, Inflector makes string manipulation in SQL simple and efficient.
46

57
## Use Cases
68

@@ -24,6 +26,24 @@ INSTALL inflector FROM community;
2426
LOAD inflector;
2527
```
2628

29+
## Quick Start
30+
31+
```sql
32+
-- Install and load the extension
33+
INSTALL inflector FROM community;
34+
LOAD inflector;
35+
36+
-- Transform a single string
37+
SELECT inflector_to_camel_case('hello_world'); -- helloWorld
38+
39+
-- Transform all column names in a struct
40+
SELECT inflect('snake', {'firstName': 'John', 'lastName': 'Doe'});
41+
-- {'first_name': John, 'last_name': Doe}
42+
43+
-- Transform all column names from a table or query
44+
SELECT * FROM inflect('kebab', read_csv('data.csv'));
45+
```
46+
2747
## Functions
2848

2949
### Case Transformation Functions
@@ -166,11 +186,55 @@ Check if a string matches a specific case or format:
166186

167187
Returns `true` or `false`.
168188

189+
**Examples:**
190+
```sql
191+
SELECT inflector_is_snake_case('hello_world') as v;
192+
┌─────────┐
193+
│ v │
194+
boolean
195+
├─────────┤
196+
│ true │
197+
└─────────┘
198+
199+
SELECT inflector_is_camel_case('HelloWorld') as v;
200+
┌─────────┐
201+
│ v │
202+
boolean
203+
├─────────┤
204+
│ false │
205+
└─────────┘
206+
207+
SELECT inflector_is_foreign_key('user_id') as v;
208+
┌─────────┐
209+
│ v │
210+
boolean
211+
├─────────┤
212+
│ true │
213+
└─────────┘
214+
```
215+
169216
### Struct and Table Column Inflection
170217

171-
Inflect the keys of a `STRUCT` or table;s column names to a target case style:
218+
The `inflect()` function is the most powerful feature, allowing you to transform all column names in a struct or table result at once.
172219

173-
- `inflect('case', struct_or_table)`
220+
Inflect the keys of a `STRUCT` or table's column names to a target case style:
221+
222+
**Syntax:**
223+
```sql
224+
inflect('case_style', struct_or_table)
225+
```
226+
227+
**Supported case styles:**
228+
- `'camel'` / `'camel_case'` → camelCase
229+
- `'class'` / `'class_case'` → ClassCase
230+
- `'snake'` / `'snake_case'` → snake_case
231+
- `'kebab'` / `'kebab_case'` → kebab-case
232+
- `'train'` / `'train_case'` → Train-Case
233+
- `'title'` / `'title_case'` → Title Case
234+
- `'table'` / `'table_case'` → table_names (pluralized snake_case)
235+
- `'sentence'` / `'sentence_case'` → Sentence case
236+
- `'upper'` / `'upper_case'` → UPPERCASE
237+
- `'lower'` / `'lower_case'` → lowercase
174238

175239
**Examples:**
176240
```sql
@@ -202,22 +266,153 @@ SELECT n FROM inflect('camel', (SELECT 1 AS counterValue, 't' AS first_name)) AS
202266

203267
## Real-World Examples
204268

205-
### Normalize Table Columns
269+
### Normalize CSV Column Names
270+
```sql
271+
-- Convert PascalCase CSV headers to snake_case
272+
SELECT * FROM inflect('snake', read_csv('UserData.csv'));
273+
-- FirstName, LastName, EmailAddress → first_name, last_name, email_address
274+
```
275+
276+
### Transform API Response Data
277+
```sql
278+
-- Convert camelCase JSON keys to snake_case for database storage
279+
CREATE TABLE users AS
280+
SELECT * FROM inflect('snake',
281+
read_json('api_response.json')
282+
);
283+
```
284+
285+
### Validate Naming Conventions
286+
```sql
287+
-- Check if all column names follow snake_case convention
288+
SELECT
289+
column_name,
290+
inflector_is_snake_case(column_name) as is_valid
291+
FROM information_schema.columns
292+
WHERE table_name = 'my_table';
293+
```
294+
295+
### Schema Migration Between Conventions
296+
```sql
297+
-- Convert a Ruby on Rails style table to JavaScript convention
298+
CREATE TABLE users_camel AS
299+
SELECT * FROM inflect('camel', users);
300+
```
301+
302+
### Generate Foreign Key Names
303+
```sql
304+
-- Create foreign key column names from table names
305+
SELECT
306+
table_name,
307+
inflector_to_foreign_key(table_name) as fk_column
308+
FROM information_schema.tables;
309+
```
310+
311+
### Pluralize Table Names
312+
```sql
313+
-- Ensure all table names are plural
314+
SELECT
315+
table_name,
316+
inflector_to_plural(table_name) as plural_name
317+
FROM information_schema.tables;
318+
```
319+
320+
### Clean and Standardize Text Data
321+
```sql
322+
-- Standardize mixed-case product categories
323+
UPDATE products
324+
SET category = inflector_to_title_case(category);
325+
```
326+
327+
### Generate Display Labels
328+
```sql
329+
-- Convert snake_case column names to human-readable titles
330+
SELECT
331+
'first_name' as column,
332+
inflector_to_title_case('first_name') as label; -- First Name
333+
```
334+
335+
## Advanced Usage
336+
337+
### Nested Struct Transformation
338+
```sql
339+
-- Inflect nested struct keys recursively
340+
SELECT inflect('camel', {
341+
'user_info': {
342+
'first_name': 'John',
343+
'last_name': 'Doe'
344+
}
345+
}) as result;
346+
```
347+
348+
### Bulk Column Validation
349+
```sql
350+
-- Find all columns that don't follow snake_case
351+
WITH column_check AS (
352+
SELECT
353+
table_name,
354+
column_name,
355+
inflector_is_snake_case(column_name) as is_snake_case
356+
FROM information_schema.columns
357+
)
358+
SELECT * FROM column_check WHERE NOT is_snake_case;
359+
```
360+
361+
### Data Pipeline Transformation
206362
```sql
207363
SELECT * FROM inflect('snake', read_csv('example.csv'));
208364
```
209365

366+
## Performance Considerations
367+
368+
- **Transformation functions** are highly optimized and work efficiently on large datasets
369+
- **The `inflect()` function** operates on column metadata, not data, making it very fast
370+
- **Predicate functions** can be used in WHERE clauses and are optimized for filtering
371+
210372
## Tips and Best Practices
211373

212-
1. **Use the right case for your project**: Consistent naming improves maintainability
213-
2. **Validate data**: Use predicate functions to enforce naming conventions
214-
3. **Automate schema migrations**: Use `inflect()` to convert column names in bulk
215-
4. **Combine with DuckDB's JSON/struct features**: Inflect nested data structures
216-
5. **Test with sample data**: Use the provided test cases as a reference
374+
1. **Use the right case for your project**: Consistent naming improves maintainability and reduces errors
375+
2. **Validate data early**: Use predicate functions in data quality checks during ETL
376+
3. **Automate schema migrations**: Use `inflect()` to convert column names in bulk rather than manual renaming
377+
4. **Combine with DuckDB's JSON/struct features**: Inflect nested data structures from APIs and config files
378+
5. **Standardize imports**: Apply inflection when reading external data (CSV, JSON, Parquet)
379+
6. **Use table_case for database tables**: Automatically pluralizes and converts to snake_case
380+
7. **Document your conventions**: Choose a case style and stick with it across your project
381+
382+
## Error Handling
383+
384+
The extension provides clear error messages for common issues:
385+
386+
```sql
387+
-- Unknown case style
388+
SELECT inflect('unknown', {'foo': 1});
389+
-- Error: Unknown inflection 'unknown'. Supported: camel, class, snake, kebab, train, title, table, sentence, upper, lower
390+
391+
-- Invalid arguments
392+
SELECT inflect('snake');
393+
-- Error: inflect() requires exactly two arguments: function name and value to inflect
394+
```
395+
396+
## Frequently Asked Questions
397+
398+
**Q: What's the difference between `class_case` and `pascal_case`?**
399+
A: They're the same! Both produce `PascalCase` output.
400+
401+
**Q: Can I use `inflect()` on a table with millions of rows?**
402+
A: Yes! The `inflect()` function only transforms column *names*, not the data itself, so it's extremely fast regardless of table size.
403+
404+
**Q: Does `table_case` always pluralize?**
405+
A: Yes, `table_case` converts to snake_case and pluralizes the name (e.g., `User``users`).
406+
407+
**Q: Can I chain transformations?**
408+
A: Yes! You can nest `inflect()` calls or pipe results through multiple transformations.
217409

218410
## Contributing
219411

220-
The Inflector extension is open source and developed by [Query.Farm](https://query.farm).
412+
The Inflector extension is open source and developed by [Query.Farm](https://query.farm). Contributions, bug reports, and feature requests are welcome!
413+
414+
- GitHub: [Query-farm/inflector](https://github.com/Query-farm/inflector)
415+
- Website: [query.farm](https://query.farm)
221416

222417
## License
223418

duckdb

Submodule duckdb updated 656 files

0 commit comments

Comments
 (0)