Skip to main content

Overview

The CamelCasePlugin 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 called person_table with columns first_name and last_name in the database:
Generated SQL (SQLite):
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: boolean
Default: false
If true, camelCase is transformed into upper case SNAKE_CASE. Example:

underscoreBeforeDigits

Type: boolean
Default: false
If true, an underscore is added before each digit when converting camelCase to snake_case. Example:

underscoreBetweenUppercaseLetters

Type: boolean
Default: false
If true, an underscore is added between consecutive upper case letters when converting from camelCase to snake_case. Example:

maintainNestedObjectKeys

Type: boolean
Default: false
If true, nested object’s keys will not be converted to camelCase. Example:

Methods

transformQuery

Transforms all identifiers in the query from camelCase to snake_case before execution. Source: ~/workspace/source/src/plugin/camel-case/camel-case-plugin.ts:135

transformResult

Transforms all keys in the result rows from snake_case to camelCase after execution. Source: ~/workspace/source/src/plugin/camel-case/camel-case-plugin.ts:139

Custom Conversion Logic

You can override the plugin’s conversion methods for custom behavior:

snakeCase

Converts a camelCase string to snake_case. Override this method to customize the conversion. Source: ~/workspace/source/src/plugin/camel-case/camel-case-plugin.ts:167

camelCase

Converts a snake_case string to camelCase. Override this method to customize the conversion. Source: ~/workspace/source/src/plugin/camel-case/camel-case-plugin.ts:171

How It Works

  1. Query Transformation: When a query is built, the plugin uses a SnakeCaseTransformer to convert all identifier names from camelCase to snake_case
  2. Result Transformation: After query execution, the plugin recursively processes all result rows, converting keys from snake_case to camelCase
  3. Nested Objects: By default, nested objects and arrays are also processed recursively (unless maintainNestedObjectKeys is true)

See Also