Detalhes do pacote

mdb-reader

andipaetzold15.5kMIT3.1.0

JavaScript library to read data from Access databases

mdb, microsoft, access, database

readme (leia-me)

npm tests downloads license semantic-release

MDB Reader

JavaScript library to read data from Access databases.

Installation

npm install mdb-reader

or

yarn add mdb-reader

Compatibility

Node / JavaScript

Access Database versions

  • Access 97 (Jet 3)
  • Access 2000, XP and 2003 (Jet 4)
  • Access 2010 (ACE14)
  • Access 2013 (ACE15)
  • Access 2016 (ACE16)
  • Access 2019 (ACE17)

Encryption

  • Jet
  • Office Agile
  • Office RC4 Crypto API

Dependencies

To decrypt databases, this library requires a few dependencies:

Usage

import { readFileSync } from "fs";
import MDBReader from "mdb-reader";

const buffer = readFileSync("database.mdb");
const reader = new MDBReader(buffer);

reader.getTableNames(); // ['Cats', 'Dogs', 'Cars']

const table = reader.getTable("Cats");
table.getColumnNames(); // ['id', 'name', 'color']
table.getData(); // [{id: 5, name: 'Ashley', color: 'black'}, ...]

Examples

  • browser - Running in the browser with parcel
  • to-json - CLI script that accepts a database file name and outputs the data as JSON
  • sveltekit - Running with SvelteKit

API

MDBReader

class MDBReader {
    /**
     * @param buffer Buffer of the database.
     */
    constructor(
        buffer: Buffer,
        options?: {
            password?: string;
        }
    );

    /**
     * Date when the database was created
     */
    getCreationDate(): Date | null;

    /**
     * Database password
     */
    getPassword(): string | null;

    /**
     * Default sort order
     */
    getDefaultSortOrder(): Readonly<SortOrder>;

    /**
     * Returns an array of table names.
     *
     * @param normalTables Includes user tables.
     * @param systemTables Includes system tables.
     * @param linkedTables Includes linked tables.
     */
    getTableNames({
        normalTables,
        systemTables,
        linkedTables,
    }?: {
        normalTables: boolean;
        systemTables: boolean;
        linkedTables: boolean;
    }): string[];

    /**
     * Returns a table by its name.
     *
     * @param name Name of the table. Case sensitive.
     */
    getTable(name: string): Table;
}

Table

class Table {

    /**
     * Name of the table
     */
    readonly name: string,

    /**
     * Number of rows.
     */
    readonly rowCount: number;

    /**
     * Number of columns.
     */
    readonly columnCount: number;

    /**
     * Returns an ordered array of all column definitions.
     */
    getColumns(): Column[];

    /**
     * Returns a column definition by its name.
     *
     * @param name Name of the column. Case sensitive.
     */
    getColumn(name: string): Column;

    /**
     * Returns an ordered array of all column names.
     */
    getColumnNames(): string[];

    /**
     * Returns data from the table.
     *
     * @param columns Columns to be returned. Defaults to all columns.
     * @param rowOffset Index of the first row to be returned. 0-based. Defaults to 0.
     * @param rowLimit Maximum number of rows to be returned. Defaults to Infinity.
     */
    getData<TRow extends {
        [column in TColumn]: Value;
        TColumn extends string = string;
    }>(options?: {
        columns?: ReadonlyArray<TColumn>;
        rowOffset?: number;
        rowLimit?: number;
    }): TRow[];
}

Column

interface Column {
    /**
     * Name of the table
     */
    name: string;

    /**
     * Type of the table
     */
    type: ColumnType;
    size: number;

    fixedLength: boolean;
    nullable: boolean;
    autoLong: boolean;
    autoUUID: boolean;

    /**
     * Only exists if type = 'numeric'
     */
    precision?: number;

    /**
     * Only exists if type = 'numeric'
     */
    scale?: number;
}

Data Types

The data types returned by Table.getData() depends on the column type. Null values are always returned as null.

Column Type JavaScript Type
bigint bigint
binary Buffer
boolean boolean
byte number
complex number
currency string
datetime Date
datetimeextended string
double number
float number
integer number
long number
memo string
numeric string
ole Buffer
repid string
text string

Development

Build

To build the library, first install the dependencies, then run npm run build for a single build or npm run watch for automatic rebuilds.

npm install
npm run build

Tests

To run the tests, first install the dependencies, then run npm test. Watch mode can be started with npm test -- --watch.

npm install
npm test

Resources

MDB Tool

GitHub

Set of applications to read and write Access files, written in C. Main source of knowledge about the file structure and algorithms to extract data from it.

Jackcess

Jackcess

Java library to read and write Access files. It inspired the interface of this library. The databases used for testing are copied from the repository.

The unofficial MDB Guide

Tech Specs for the JET format used by Access 1997-2010

License

MIT

changelog (log de mudanças)

3.1.0 (2025-02-28)

Features

  • support fast-xml-parser v5 (505ce6b)

3.0.1 (2025-02-17)

Bug Fixes

  • do not skip last char when decompressing text where the last characters are uncompressed (#360) (30bea44)

3.0.0 (2023-11-28)

Bug Fixes

  • exactOptionalPropertyTypes TS option compatibility (#300) (31b129a)
  • set conditional exports in package.json (#299) (ef65273)
  • use named import for fast-xml-parser (#273) (314e786), closes #170

Code Refactoring

  • use private class fields/methods (2fef138)

Features

BREAKING CHANGES

  • browser/node must support private class fields/methods
  • drop node 16 support
  • ColumnType is not a TypeScript enum anymore:
  • ColumnType is a union type
  • ColumnTypes a map for easier usage of ColumnType
  • drop node 14 support

3.0.0-next.6 (2023-11-25)

Bug Fixes

  • exactOptionalPropertyTypes TS option compatibility (#300) (31b129a)

3.0.0-next.5 (2023-11-24)

Bug Fixes

  • set conditional exports in package.json (#299) (ef65273)

3.0.0-next.4 (2023-09-20)

Code Refactoring

  • use private class fields/methods (2fef138)

BREAKING CHANGES

  • browser/node must support private class fields/methods

3.0.0-next.3 (2023-06-08)

Bug Fixes

  • Long Text fields with ~2k+ characters (#282) (ad81f42)

Features

BREAKING CHANGES

  • drop node 16 support

2.2.6 (2023-06-08)

Bug Fixes

  • Long Text fields with ~2k+ characters (#282) (ad81f42)

3.0.0-next.2 (2023-02-04)

Bug Fixes

Features

BREAKING CHANGES

  • ColumnType is not a TypeScript enum anymore:
    • ColumnType is a union type
    • ColumnTypes a map for easier usage of ColumnType

3.0.0-next.1 (2023-02-04)

Features

BREAKING CHANGES

  • drop node 14 support

2.2.5 (2022-10-25)

Bug Fixes

2.2.4 (2022-05-27)

Bug Fixes

  • use unboxed bigint type instead of BigInt (2d12670)

2.2.3 (2022-05-24)

Bug Fixes

  • correctly read number of variable columns of Jet3 dbs (#222) (a92de98)

2.2.2 (2022-02-28)

Bug Fixes

  • performance of getData with offset/limit (#177) (de6bd37), closes #48

2.2.1 (2022-02-26)

Bug Fixes

  • export constructor Options type (deb95fe)

2.2.0 (2022-02-26)

Features

  • export separate browser module (5b7012d)

2.2.0-next.1 (2022-02-26)

Bug Fixes

  • use default import for browserify-aes (4485952)

Features

  • create separate browser module (d59e8b9)

2.1.2 (2022-02-22)

Bug Fixes

  • handle non-ascii characters in Jet3 databases (#173) (840c79d), closes #172

2.1.1 (2022-02-20)

Bug Fixes

  • use default import for fast-xml-parser (#169) (4a2ce3e)

2.1.0 (2022-01-14)

Features

  • support Office Agile & RC4 Crypto API encrypted databases (#150) (6f017b0)

2.0.0 (2022-01-10)

Features

BREAKING CHANGES

  • remove MDBReader.buffer
  • make package ESM only
  • The package doesn't include a bundled version anymore
  • remove MDBReader.getFormat()
  • drop node 12 support

2.0.0-next.11 (2022-01-10)

Bug Fixes

Features

  • remove MDBReader.buffer (abb01bb)

BREAKING CHANGES

  • remove MDBReader.buffer

2.0.0-next.10 (2022-01-08)

Features

  • add getCreationDate (dbd4a25)
  • add getDefaultSortOrder (3a1d879)
  • add getPassword (8500f18)
  • decrypt "protected" mdb files (ad17ae3), closes #90
  • make ColumnType an enum & export ValueMap (332fa99)

2.0.0-next.9 (2021-12-30)

Features

2.0.0-next.8 (2021-12-30)

Bug Fixes

  • fully specify file paths in imports (c9ce276)

2.0.0-next.7 (2021-12-21)

Bug Fixes

Features

BREAKING CHANGES

  • make package ESM only

2.0.0-next.6 (2021-11-16)

Bug Fixes

  • handle tables with over 256 cols (incl. deleted) (#111) (e5f0d19)
  • incorrect boolean values in tables with inserted columns (#124) (0d4b78c)
  • mixed endianness of guids (#118) (ac7790c)
  • round milliseconds in datetime parser (#123) (b1b4379)

2.0.0-next.5 (2021-10-16)

  • feat!: do not publish bundled version (#114) (7d3fd1b), closes #114

BREAKING CHANGES

  • The package doesn't include a bundled version anymore

2.0.0-next.4 (2021-10-11)

  • feat!: remove MDBReader.getFormat() (#112) (7600737), closes #112

BREAKING CHANGES

  • remove MDBReader.getFormat()

2.0.0-next.3 (2021-10-11)

Bug Fixes

  • don't throw for BigInt and Date/Time Extended (e02ef3a)

2.0.0-next.2 (2021-10-10)

Features

2.0.0-next.1 (2021-10-10)

Features

BREAKING CHANGES

  • drop node 12 support

1.2.1 (2022-01-10)

Bug Fixes

1.2.0 (2022-01-08)

Features

1.1.0 (2022-01-06)

Features

1.0.10 (2021-12-05)

Bug Fixes

1.0.9 (2021-11-16)

Bug Fixes

  • incorrect boolean values in tables with inserted columns (#124) (0d4b78c)

1.0.8 (2021-11-05)

Bug Fixes

  • round milliseconds in datetime parser (#123) (b1b4379)

1.0.7 (2021-10-22)

Bug Fixes

1.0.6 (2021-10-11)

Bug Fixes

  • handle tables with over 256 cols (incl. deleted) (#111) (e5f0d19)

1.0.5 (2021-10-11)

Bug Fixes

  • don't throw for BigInt and Date/Time Extended (e02ef3a)

1.0.4 (2021-10-04)

Bug Fixes

  • max precision for money & numeric data (9744b6c)

1.0.3 (2021-09-07)

Bug Fixes

  • null values in tables with deleted columns (#97) (cb95282)

1.0.2 (2021-08-17)

Bug Fixes

  • error message when page has unexpected type (5d753e6)

1.0.1 (2021-07-03)

Bug Fixes

1.0.0 (2021-06-02)

BREAKING CHANGES

  • drop support of node v10 & v15; add v16 support (#75) (6f894b6)
    • node 10 (LTS) is EOL
    • node 15 is EOL
    • node 16 is current

0.2.0 (2021-03-31)

Features

0.1.7 (2021-03-25)

Bug Fixes

0.1.6 (2021-03-25)

Bug Fixes

  • move @types/node to dev dependencies (#49) (a70ea2c)

0.1.5 (2021-03-18)

Bug Fixes

  • RangeError & empty array when using getData with rowOffset (#46) (82fd481)

0.1.4 (2021-03-12)

Bug Fixes

0.1.3 (2020-12-02)

Bug Fixes

  • set rollup output.exports to default for cjs (5d4d311)
  • use types prop in package.json for type defs (7616862)