TypeORM Dmdb Dialect
typeorm-dm is a database dialect package that enables TypeORM to connect and interact with Dameng (DMDB) databases. It acts as an adapter layer between TypeORM and the `dmdb` npm package, which is the official Node.js driver for Dameng. The current stable version is 1.0.43524. The project appears to have a fairly active release cadence, with multiple updates in 2024 and 2025, often driven by changes in the underlying `dmdb` driver. A key differentiator is its explicit requirement to use `DmdbDataSource` rather than relying on TypeORM's automatic driver loading, and its handling of features like `simple-enum` columns by converting them to `varchar` with check constraints. It specifically dropped runtime dependency on `oracledb` in v1.0.26038, highlighting its focus solely on Dameng.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'initialize')
cause Attempting to use `new DataSource(...)` with `type: 'dmdb'` instead of explicitly importing `DmdbDataSource`.fixImport `DmdbDataSource` directly and instantiate it: `import { DmdbDataSource } from 'typeorm-dm'; const AppDataSource = new DmdbDataSource({ /* ... */ });` -
Error: "dmdb" is not a valid database type. Please specify one of the following: "mysql", "mariadb", "postgres", "sqlite", "oracle", "mssql", "sap", "cockroachdb", "cordova", "react-native", "nativescript", "sqljs", "mongodb", "aurora-data-api", "aurora-data-api-pg", "expo", "capacitor", "spanner".
cause TypeORM's core `DataSource` does not natively recognize `dmdb` as a `type` option.fixWhen using `DmdbDataSource`, set `type: "oracle"` and `innerType: "dmdb"` in your configuration object. The `type` field uses TypeORM's internal `oracle` driver compatibility layer.
Warnings
- breaking The underlying `dmdb` driver's parameter binding strategy changed, requiring a synchronous update to `typeorm-dm`.
- breaking The `dmdb` driver's auto-commit configuration policy changed, necessitating updates in `typeorm-dm`.
- gotcha The package specifically handles `enum` and `simple-enum` column types by converting them to `varchar` with `CHECK` constraints in the database. This differs from native enum support in some other database systems.
- gotcha Unlike TypeORM's automatic driver loading based on the `type` field, `DmdbDataSource` must be explicitly imported and used. Setting `type: "dmdb"` in a standard `DataSource` config will not work.
- gotcha Older versions might have issues with mixed `?` and `:` parameter placeholders in queries.
- deprecated Runtime dependency on the `oracledb` module was removed.
Install
-
npm install typeorm-dm -
yarn add typeorm-dm -
pnpm add typeorm-dm
Imports
- DmdbDataSource
const DmdbDataSource = require('typeorm-dm').DmdbDataSourceimport { DmdbDataSource } from 'typeorm-dm' - DataSourceOptions for Dm
import { DataSourceOptions } from 'typeorm'; const config: DataSourceOptions = { type: 'oracle', innerType: 'dmdb', ... } - reflect-metadata
import 'reflect-metadata'
Quickstart
import "reflect-metadata";
import { DmdbDataSource } from "typeorm-dm";
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class Photo {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column('text')
description: string;
@Column()
filename: string;
@Column()
views: number;
@Column()
isPublished: boolean;
}
// Ensure Dameng is running and accessible, e.g., via Docker or a local installation.
// Replace connection details with your actual Dameng server information.
const AppDataSource = new DmdbDataSource({
type: "oracle", // TypeORM's internal type for Oracle/DMDB compatibility
innerType: "dmdb", // Specific inner type for Dameng
url: process.env.DM_DATABASE_URL ?? "dm://SYSDBA:SYSDBA@localhost:5236?schema=SYSDBA", // Recommended to use URL
host: "localhost",
port: 5236,
username: process.env.DM_USERNAME ?? "SYSDBA",
password: process.env.DM_PASSWORD ?? "SYSDBA",
schema: process.env.DM_SCHEMA ?? "SYSDBA",
entities: [Photo],
synchronize: true,
logging: false,
});
AppDataSource.initialize()
.then(async () => {
console.log("Data Source has been initialized!");
const photoRepository = AppDataSource.getRepository(Photo);
const newPhoto = new Photo();
newPhoto.name = "My First Photo";
newPhoto.description = "Just a test photo";
newPhoto.filename = "photo.jpg";
newPhoto.views = 1;
newPhoto.isPublished = true;
await photoRepository.save(newPhoto);
console.log("Photo saved successfully.");
const allPhotos = await photoRepository.find();
console.log("All photos:", allPhotos);
await AppDataSource.destroy();
console.log("Data Source has been destroyed!");
})
.catch((error) => console.error("Error during Data Source initialization:", error));