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

bs-mysql2

v10.0.2

Published

ReasonML bindings to the mysql2 library.

Downloads

52

Readme

NPM Build Status Coverage Status

bs-mysql2

ReasonML bindings to the mysql2 library.

This is a very rough implementation that will enable very simple use cases.

Initially this was just a copy of bs-mysql.

Why?

The main difference between these bindings and the bs-mysql bindings is the use of the mysql2 library / driver over the mysql (version 1) driver. You can see the reasoning behind the new mysql2 driver here: History and Why MySQL2

Version 2

Version 2 of this driver removed most of the API surface area. This is now intended as a module which better interfaces are built on top of, yet it still quite usable.

However, if you are looking for a higher level interface then you should look at the bs-sql-common library. This library can be used along side bs-sql-common as a data provider.

Status

Not all of the mysql2 library features are implemented but there is a usable implementation of the Promise based wrapper and Named Placeholders.

NOTE: If you're trying to run the tests on macOS then you will need to: brew install watchman

Usage

Standard Callback Interface

Standard Query Method

let conn
  = MySql2.Connection.connect(~host=127.0.0.1, ~port=3306, ~user="root", ());

MySql2.execute(conn, "SHOW DATABASES", None, res => {
    switch res {
    | `Error(e) => Js.log2("ERROR: ", e)
    | `Select(select) => Js.log2("SELECT: ", select)
    | `Mutation(mutation) => Js.log2("MUTATION: ", mutation)
    }
  MySql2.close(conn);
});

Prepared Statements

Named Placeholders
let conn
  = MySql2.Connect.connect(~host=127.0.0.1, ~port=3306, ~user="root", ());

let named = MySql2.Params.named(
  Json.Encode.object_([
    ("x", Json.Encode.int(1)),
    ("y", Json.Encode.int(2)),
  ])
);

MySql2.execute(conn, "SELECT :x + :y AS result", Some(named), res => {
    switch res {
    | `Error(e) => Js.log2("ERROR: ", e)
    | `Select(select) => Js.log2("SELECT: ", select)
    | `Mutation(mutation) => Js.log2("MUTATION: ", mutation)
    }
  }
  MySql2.close(conn);
});
Unnamed Placeholders
let conn
  = MySql2.Connection.connect(~host=127.0.0.1, ~port=3306, ~user="root", ());

let positional = MySql2.Params.positional(
  Belt_Array.map([|5, 6|], Json.Encode.int) |> Json.Encode.jsonArray
);

MySql2.execute(conn, "SELECT 1 + ? + ? AS result", Some(positional), res => {
    switch res {
    | `Error(e) => Js.log2("ERROR: ", e)
    | `Select(rows, meta) => Js.log2("SELECT: ", rows, meta)
    | `Mutation(count, id) => Js.log2("MUTATION: ", count, id)
    }
  }
  MySql2.close(conn);
});

How do I install it?

Inside of a BuckleScript project:

yarn install --save bs-mysql2 @glennsl/bs-json

Then add bs-mysql2 and @glennsl/bs-json to your bs-dependencies in bsconfig.json:

{
  "bs-dependencies": ["bs-mysql2", "@glennsl/bs-json"]
}

How do I use it?

bs-mysql2 examples assume that there is:

  • a datatabase named test inside mysql: create it by running create database test
  • you are using mysql_native_password as authentication for the root user
    • see https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server

Use it in your project

See the Usage section above...

Run the examples

yarn run examples:simple
yarn run examples:prepared-statements

What's missing?

Mostly everything...