3.0.0 • Published 12 months ago

mdb-reader v3.0.0

Weekly downloads
376
License
MIT
Repository
github
Last release
12 months ago

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'}, ...]

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 TypeJavaScript Type
bigintbigint
binaryBuffer
booleanboolean
bytenumber
complexnumber
currencystring
datetimeDate
datetimeextendedstring
doublenumber
floatnumber
integernumber
longnumber
memostring
numericstring
oleBuffer
repidstring
textstring

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

3.0.0-next.6

12 months ago

3.0.0-next.5

12 months ago

3.0.0

12 months ago

3.0.0-next.4

1 year ago

3.0.0-next.3

1 year ago

2.2.6

1 year ago

3.0.0-next.2

2 years ago

3.0.0-next.1

2 years ago

2.2.5

2 years ago

2.2.3

3 years ago

2.2.4

2 years ago

2.2.0-next.1

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.2

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

2.0.0-next.8

3 years ago

2.0.0-next.9

3 years ago

2.0.0-next.7

3 years ago

2.0.0-next.10

3 years ago

2.0.0-next.11

3 years ago

1.2.1

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.10

3 years ago

2.0.0-next.6

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

2.0.0-next.5

3 years ago

1.0.7

3 years ago

2.0.0-next.4

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

2.0.0-next.2

3 years ago

2.0.0-next.3

3 years ago

2.0.0-next.1

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago