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

mariadb-transact

v0.7.4

Published

A transaction manager for the mariasql module that uses promises.

Downloads

34

Readme

mariadb-transact

A transaction manager for the node.js MariaSQL module that uses promises. This module is essentially a convenience wrapper for node-mariasql with some extended functionality.

Install

npm install mariadb-transact

Example

CoffeeScript

TransactionManager = require "mariadb-transact"

sqlcfg =
  user: "USER"
  password: "PASSWORD"
  host: "HOST"
  db: "DATABASE"
  metadata: true

transact = new TransactionManager(sqlcfg)

transact.init().then ->
  transact.basic().then (sql) ->
    sql.fetchArray("SHOW DATABASES")
    .then (res) ->
      console.log res
      
  .then ->
    transact.begin()
    
  .then (sql) ->
    sql.command("DELETE FROM mytable WHERE id=3")
    
    .then (res) ->
      console.log res
      sql.commit()
      
    .then ->
      transact.close()
      
.catch (err) ->
  console.error err.stack

JavaScript

var TransactionManager = require("mariadb-transact");

var sqlcfg = {
user: "USER",
password: "PASSWORD",
host: "HOST",
db: "DATABASE",
metadata: true
};

var transact = new TransactionManager(sqlcfg);

transact.init().then(function() {
  return transact.basic().then(function(sql) {
    return sql.fetchArray("SHOW DATABASES").then(function(res) {
      return console.log(res);
    });
  }).then(function() {
    return transact.begin();
  }).then(function(sql) {
    return sql.command("DELETE FROM mytable WHERE id=3").then(function(res) {
      console.log(res);
      return sql.commit();
    }).then(function() {
      return transact.close();
    });
  });
})["catch"](function(err) {
  return console.error(err.stack);
});

API

require('mariadb-transact') returns a TransactionManager object.

TransactionManager properties

  • log - < Logger > - A Winston-style logging object. Default is a stub.

TransactionManager events

  • error(< Error >err) - An error occurred.

  • init() - The manager has been initialized.

TransactionManager methods

  • contructor(< object >config) - Create and return a new TransactionManager instance. The config object is equivalent to the Client config object in the node-mariasql library, but takes an additional parameter and extends on the metadata parameter:

    • metadata - < boolean > - Automatically convert result data into appropriate types. Default: false

    • poolsize - < integer > - Size of the connection pool. Default: 20

  • init() - < Promise >() - Initializes the database connection and returns a promise that fulfills when it is connected.

  • basic() - < Promise>(< Client >client) - Returns a promise that fulfills with a non-transaction-safe Client object.

  • begin() - < Promise>(< Client >client) - Returns a promise that fulfills with a transaction-safe Client object from the connection pool. Transaction-safe Client objects must always be completed using their commit or rollback method, otherwise they will not complete or return to the pool.

  • close() - < Promise >() - Closes connection and returns a promise that fulfills when complete.

Client methods

  • command(< string >query, < object >params) - < Promise >(< object >result) - Executes SQL query, returns promise that fulfills with a result object containing the following elements:

    • affectedRows - < integer > - Number of rows affected by the command.

    • insertId - < integer > - Last auto-increment ID of insert command.

    • numRows - < integer > - Number of returned rows.

  • commit() - < Promise >() - Commits a transaction. Promise fulfulls when done.

  • fetchArray(< string >sql, < object >params) - < Promise >(< Array >results) - Executes SQL query, returns promise that fulfills with a result array.

  • fetchOne(< string >sql, < object >params) - < Promise >(< object >result) - Executes SQL query, returns promise that fulfills with a single result object. This command always returns the first result row of the query.

  • rollback() - < Promise >() - Rolls back a transaction. Promise fulfulls when done.