0.15.1 • Published 3 years ago

minidb v0.15.1

Weekly downloads
3
License
BSD
Repository
github
Last release
3 years ago

minidb Build Status

A small object wrapper for PostgreSQL and SQLite. It has very little sugar and is intentionally low-level. It does not do migrations, relationships, identity management, or any other magic.

Installation

npm install minidb

Usage

import {PersistentObject, SQLite} from 'minidb';

export default class User extends PersistentObject {
  static get tableName() {
    return 'users';
  }

  static get columns() {
    return [
      { name: 'name', column: 'name', type: 'string', null: false },
      { name: 'email', column: 'email', type: 'string', null: false },
      { name: 'age', column: 'age', type: 'integer', null: false },
      { name: 'height', column: 'height', type: 'double' },
      { name: 'birthDate', column: 'birth_date', type: 'date' }
    ];
  }
}

PersistentObject.register(User);

// use the API
const db = new SQLite({file: 'users.db'});
//const db = new Postgres({db: 'dbname = minidb'});

await db.open();

const setupScript = `
DROP TABLE IF EXISTS users;

CREATE TABLE users (
  id bigserial NOT NULL,
  name text NOT NULL,
  email text NOT NULL,
  age bigint NOT NULL,
  height double precision,
  birth_date date,
  created_at double precision,
  updated_at double precision
);

CREATE UNIQUE INDEX idx_user_email ON users (email);
`;

await db.execute(setupScript);

const user = await User.findOrCreate(db, {name: 'John', email: 'john@example.com', age: 30});

user.height = 72.3;

await user.save();
0.15.1

3 years ago

0.15.0

3 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.5

5 years ago

0.13.4

5 years ago

0.13.3

5 years ago

0.13.2

5 years ago

0.13.1

5 years ago

0.13.0

5 years ago

0.12.11

6 years ago

0.12.10

6 years ago

0.12.9

6 years ago

0.12.8

6 years ago

0.12.7

6 years ago

0.12.6

6 years ago

0.12.5

7 years ago

0.12.4

7 years ago

0.12.3

7 years ago

0.12.2

7 years ago

0.12.1

7 years ago

0.12.0

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.0

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.0

7 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.28

8 years ago

0.0.27

8 years ago

0.0.26

8 years ago

0.0.25

8 years ago

0.0.24

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago