Overview
TheCamelCasePlugin converts snake_case identifiers in the database into camelCase in the JavaScript side. This allows you to use JavaScript naming conventions in your code while maintaining SQL naming conventions in the database.
Installation
Usage Example
Assuming you have a table calledperson_table with columns first_name and last_name in the database:
Everything must be defined in camelCase in the TypeScript code: table names, columns, schemas, everything. When using the
CamelCasePlugin, Kysely works as if the database was defined in camelCase.Constructor Options
upperCase
Type:booleanDefault:
false
If true, camelCase is transformed into upper case SNAKE_CASE.
Example:
underscoreBeforeDigits
Type:booleanDefault:
false
If true, an underscore is added before each digit when converting camelCase to snake_case.
Example:
underscoreBetweenUppercaseLetters
Type:booleanDefault:
false
If true, an underscore is added between consecutive upper case letters when converting from camelCase to snake_case.
Example:
maintainNestedObjectKeys
Type:booleanDefault:
false
If true, nested object’s keys will not be converted to camelCase.
Example:
Methods
transformQuery
transformResult
Custom Conversion Logic
You can override the plugin’s conversion methods for custom behavior:snakeCase
camelCase
How It Works
- Query Transformation: When a query is built, the plugin uses a
SnakeCaseTransformerto convert all identifier names from camelCase to snake_case - Result Transformation: After query execution, the plugin recursively processes all result rows, converting keys from snake_case to camelCase
- Nested Objects: By default, nested objects and arrays are also processed recursively (unless
maintainNestedObjectKeysistrue)