1.9.0 ā€¢ Published 5 years ago

webiny-entity-mysql v1.9.0

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

webiny-entity-mysql

A MySQL driver for entity layer.

Installation

yarn add webiny-entity-mysql

Setup

The driver works with the mysql package - currently the most popular JavaScript package for interacting with MySQL databases. Depending on your needs, use it to create a connection or pool, and just pass it to the entity driver.

If you are not familiar with the mysql package, please visit the official GitHub page to learn more about it.

The following code shows how to configure and assign MySQL driver to the Entity component.

import { MySQLDriver } from "webiny-entity-mysql";
import { Entity as BaseEntity } from "webiny-entity";
import mysql from "mysql";

const connection = mysql.createConnection({
    host: "localhost",
    port: 32768,
    user: "root",
    password: "dev",
    database: "webiny",
    timezone: "Z",
    connectionLimit: 100
});

class Entity extends BaseEntity {}

Entity.driver = new MySQLDriver({ connection });

export default Entity;

After the driver has been set, you can start defining your entities, for example:

import Entity from "./mysqlEntity.js";
ā€‹
class User extends Entity {
    constructor() {
        super();
        this.attr('firstName').char();
        this.attr('lastName').char();
    }
}
1.9.0

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago