Git Product home page Git Product logo

mdb-reader's Introduction

npm node tests downloads license semantic-release

MDB Reader

Node Library to read data from Access databases.

Installation

$ npm install mdb-reader

or

$ yarn add mdb-reader

Compatibility

Node / JavaScript

Node 10, 12, 14, and 15

The library is very likely to work in the browser with buffer for the browser (untested).

Access Database versions

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

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

    /**
     * Buffer of the database.
     */
    readonly buffer: Buffer;

    getFormat(): "Jet3" | "Jet4";

    /**
     * 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]: number | string | Buffer | Date | boolean | null;
        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:
        | "boolean"
        | "byte"
        | "integer"
        | "long"
        | "currency"
        | "float"
        | "double"
        | "datetime"
        | "binary"
        | "text"
        | "ole"
        | "memo"
        | "repid"
        | "numeric"
        | "complex";
    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
boolean boolean
byte number
integer number
long number
currency string
float number
double number
datetime Date
binary Buffer
text string
ole Buffer
memo string
repid string
numeric string
complex number

Development

Build

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

$ yarn install
$ yarn build

Tests

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

$ yarn install
$ yarn 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.

License

MIT

mdb-reader's People

Contributors

andipaetzold avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.