npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tramway-connection-mysql

v1.3.0

Published

A Provider that permits a Tramway application to connect to a MySQL database

Downloads

7

Readme

Tramway MySQLProvider is a simple Provider add-on to simplify the process of implementing calls to MySQL databases and provides an async/await wrapper on the mysql module.

Installation:

  1. npm install tramway-connection-mysql --save

Documentation

Recommended Folder Structure in addition to Tramway

  • config
  • providers
  • repositories
  • entities

MySQLProvider

The MySQLProvider is a derived Provider which follows the same interface.

Configuration parameters

Please refer to https://github.com/mysqljs/mysql#connection-options for full connection options.

| Parameter | Environment Variable | Default | Usage | | --- | --- | --- | --- | | host | MYSQL_HOST | localhost | The host of your MySQL database | | username | MYSQL_USERNAME | | The username for the database | | password | MYSQL_PASSWORD | | The password for the database | | database | MYSQL_DATABASE | | The name of the default database to connect to | | port | MYSQL_PORT | 3306 | The port for the database |

Getting started

It is recommended to make a config file with the core MySQL configuration and make an extension class to handle it before injecting that extension class into the Repository to work with the rest of Tramway's built-in features. The alternative to the extension class is calling the config parameters with the Repository every time the repository is used instead of just importing the provider to the repository.

Quick install with dependency injection:

Parameters:

In src/config/parameters/global/index.js add the following:

import {parameters as mysql} from 'tramway-connection-mysql';

export {
    mysql,
}

Services:

In src/config/services/index.js add the following:

import { services as mysql } from 'tramway-connection-mysql';

export {
    ...mysql,
}

Manually

In your config folder add a 'mysql' file.

mysql.js:

const {
    MYSQL_HOST,
    MYSQL_PORT,
    MYSQL_USERNAME,
    MYSQL_PASSWORD,
    MYSQL_DATABASE
} = process.env;

const settings = {
    host: MYSQL_HOST,
    port: MYSQL_PORT,
    username: MYSQL_USERNAME,
    password: MYSQL_PASSWORD,
    database: MYSQL_DATABASE,
};

export default settings;

Note, the same can be achieved using your environment variables and passing the declaration from your instantiated .env to the placeholders in the above example.

To get the most of it, pass the provider to your Repository class.

import MySQLProvider, {repositories} from 'tramway-connection-mysql';
import options from '../config/mysql.js';

const {MySQLRepository} = repositories;

new MySQLRepository(new MySQLProvider(options), new Factory());

The following can also be easily achieved with dependency injection using tramway-core-dependency-injector.

Exposed Methods with this Library

Provider

Note, the extended MySQLProvider expects an additional parameter tableName on most methods. Using the MySQLRepository handles this for you. In addition, bulk inserts are possible.

| Function | Availability | | ----- | ----- | | getOne(id: any, tableName: string) | Available | | getMany(ids: any[], tableName: string) | Available | | get(tableName: string) | Available | | find(conditions: string/Object, tableName: string) | Available | | has(id: any, tableName: string) | Available | | hasThese(ids : any[], tableName: string) | Available | | count(conditions: any, tableName: string) | Available | | create(item: Entity/Object, tableName: string) | Available | | createMany(item: Entity/Object[], tableName: string) | Additional, creates a transaction for bulk inserts | | update(id: any, item: Entity/Object, tableName: string) | Available | | delete(id: any, tableName: string) | Available | | deleteMany(ids : any[], tableName: string) | Available | | query(query: string/Object, values: Object) | Available |

Repository

| Function | Usability | | --- | --- | | exists(id: any) | Usable | | getOne(id: any) | Usable | | get() | Usable | | create(entity: Entity) | Usable | | createMany(entities: Entity[]) | Additional | | update(entity: Entity) | Usable | | delete(id: any) | Usable | | find(condtions: string/Object) | Usable | | getMany(ids: any[]) | Usable | | count(conditions) | Usable |