Skip to content

Naming Strategy Overview

Naming strategies allow you to automatically translate between your TypeScript code (usually camelCase) and your database schema (often snake_case). This keeps your database following standard conventions while your code stays idiomatic TypeScript.

UQL comes with two built-in naming strategies:

StrategyBehavior
DefaultNamingStrategyKeeps names exactly as they are in your TypeScript code.
SnakeCaseNamingStrategyAutomatically converts camelCase to snake_case.

Configure the naming strategy when initializing your pool in your uql.config.ts. This affects both runtime queries and schema generation/migrations.

uql.config.ts
import { SnakeCaseNamingStrategy, type Config } from '@uql/core';
import { PgQuerierPool } from '@uql/core/postgres';
export const pool = new PgQuerierPool(
{ host: 'localhost', database: 'my_db' },
{
// CamelCase -> snake_case translation
namingStrategy: new SnakeCaseNamingStrategy()
}
);
export default {
pool,
migrationsPath: './migrations',
} satisfies Config;

When using SnakeCaseNamingStrategy:

  • Entity: UserAccount → table user_account
  • Field: createdAt → column created_at
  • Relations: authorId → column author_id

You can implement your own naming strategy by extending the NamingStrategy interface or inheriting from DefaultNamingStrategy.

import { DefaultNamingStrategy } from '@uql/core';
export class MyCustomNamingStrategy extends DefaultNamingStrategy {
// Add a prefix to all table names
override tableName(entityName: string): string {
return `tbl_${super.tableName(entityName)}`;
}
// Force all column names to uppercase
override columnName(propertyName: string): string {
return propertyName.toUpperCase();
}
}