Forge Database Utilities

1.4.1 · active · verified Wed Apr 22

`forge-database-utils` is a JavaScript/TypeScript package designed to provide shared database utility functions specifically for Forge services. Currently at version 1.4.1, it centralizes common database-related logic to ensure consistency and reduce code duplication across various internal Forge components like control, authentication, metadata, and UI services. Key features include a centralized definition of supported field types, utility functions for validating and querying field type properties (e.g., `isSupportedFieldType`, `getPostgresColumnType`), and functions for generating PostgreSQL-compatible base names from instance IDs. The package is developed to align with the specific architectural needs of the Forge ecosystem, serving as a foundational library rather than a general-purpose database utility. Its release cadence is typically tied to internal project development cycles, ensuring tight integration and stability within the Forge suite.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing various utility functions and types, using `getSupportedFieldTypes`, checking field type support, deriving PostgreSQL column types, handling 'Generated' field properties, and generating base names.

import { 
  getSupportedFieldTypes,
  isSupportedFieldType,
  getPostgresColumnType,
  buildGeneratedColumnDefinition,
  generateBaseName,
  type FieldType 
} from 'forge-database-utils';

// 1. Get and process supported field types
const fieldTypes = getSupportedFieldTypes();
console.log('All supported field types:', fieldTypes.slice(0, 5).join(', ') + '...');

const exampleField: FieldType = 'ShortText';
if (isSupportedFieldType(exampleField)) {
  const columnType = getPostgresColumnType(exampleField);
  console.log(`'${exampleField}' maps to PostgreSQL type: ${columnType}`);
}

// 2. Handle 'Generated' field type with properties
const generatedFieldProps = {
  data_type: 'ShortText',
  generation_type: 'VIRTUAL',
  column_defn: "first_name || ' ' || last_name"
};
const generatedColumnDef = getPostgresColumnType('Generated', generatedFieldProps);
console.log(`'Generated' field type (full name) column definition: ${generatedColumnDef}`);

// 3. Generate a PostgreSQL-compatible base name
const instanceId = 'My New Service 2024-Q2';
const baseName = generateBaseName(instanceId);
console.log(`Base name for '${instanceId}': ${baseName}`);

// Example of using the FieldType type
function displayFieldInfo(fieldType: FieldType) {
  console.log(`Processing field: ${fieldType}`);
}
displayFieldInfo('Email');

view raw JSON →