1.14.0 • Published 4 months ago

@tuilder/mysql-plus v1.14.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

MySQLPlus provides abstractions on top of the mysql2 package.

  • Automatic schema generation from javascript objects
  • Read, Write and Delete methods
  • Data changed event stream
  • Audit-trail for all DB changes
  • Fine-grain permissions
  • Hook to add object defaults
  • Qualifiers for security in a multi-tenant environment

Installation

npm install @tuilder/mysql-plus

Usage

import { IDbPermissions, MySQLPlus, EDbOperations, ETableChangeType } from '@tuilder/mysql-plus';

const db = new MySQLPlus({
  database: 'test-db',
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  defaults: (schema, table, data) => {
    return {
      ...data,
      _owner: 'fred123',
      _account: accountId,
      _type: table
    }
  }
});

db.eventStream.subscribe(e => {
  console.log(ETableChangeType[e.type], e.table, e.data);
});

const sessionPermissions: IDbPermissions = {
  default: new Set([EDbOperations.Read]),
  tables: {
    person: {
      operations: new Set([EDbOperations.Write]),
      protectedFields: new Set(['password'])
    }
  },
  qualifiers: {
    _account: accountId
  }
}

// Get a connection
const conection = await db.getConnection()

// Write some data
await db.write(permissions, 'person', { id: 'abfui1y2fsbkj', name: 'Emmanuel Clive Higgins', age: 206487, favColor: 'red, yellow and black maybe' })

// Read some data
await db.read(permissions, 'person', { where: { id: 'abfui1y2fsbkj' } })
await db.read(permissions, 'person', { columns: ['id', 'name'] })

// Update some data
await db.write(permissions, 'person', { id: 'abfui1y2fsbkj', age: 30 })

// Delete some data
await db.delete(permissions, 'person', 'abfui1y2fsbkj')

Table and field names can be provided in camelCase or snake_case. The library will convert them to snake_case for the database.

1.14.0

4 months ago

1.12.3

10 months ago

1.12.4

9 months ago

1.13.1

8 months ago

1.13.0

8 months ago

1.12.2

11 months ago

1.12.1

11 months ago

1.12.0

11 months ago

1.11.1

11 months ago

1.11.0

12 months ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.9.3

1 year ago

1.9.2

1 year ago

1.9.1

1 year ago

1.9.0

1 year ago

1.8.7

1 year ago

1.8.6

1 year ago

1.8.5

1 year ago

1.8.4

1 year ago

1.8.3

1 year ago

1.8.2

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.8

1 year ago

1.6.7

1 year ago

1.6.6

1 year ago

1.6.5

1 year ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

0.0.2

1 year ago