TypeORM Dmdb Dialect

1.0.43524 · active · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `DmdbDataSource`, define a TypeORM entity, save a new record, and retrieve all records from a Dameng database.

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));

view raw JSON →