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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@adrianfalleiro/vitess

v0.0.7

Published

An expermintal Node.js client library for [Vitess](https://vitess.io/). This client uses Protocol Buffers and connect-rpc to communicate with Vitess gRPC services.

Downloads

22

Readme

Vitess Node.js Client

An expermintal Node.js client library for Vitess. This client uses Protocol Buffers and connect-rpc to communicate with Vitess gRPC services.

Features

  • Connect to Vitess services using gRPC
  • Execute queries against Vitess databases with proper type handling
  • VStream support for change data capture
  • Type-safe interfaces using TypeScript

Supported services

  • [x] vtgate
  • [x] binlog
  • [x] vtctl
  • [x] vtcld
  • [x] tablemanager
  • [x] query

Installation

npm install vitess-node

Usage

Basic Query Execution

import { VtGate, createBindVariable } from "@adrianfalleiro/vitess";

// Create the Vitess client
const client = new VtGate({
  baseUrl: "http://localhost:15991",
});

// Execute a simple query
const result = await client.execute({
  query: {
    sql: "SELECT * FROM customer",
  },
});
console.log(result);

// Query with bind variables
const result = await client.executeBatch({
  queries: [
    {
      sql: "SELECT * FROM customer WHERE email = :email",
      bindVariables: {
        email: createBindVariable("[email protected]"),
      },
    },
  ],
});

Streaming Query Results

import { VtGate } from "@adrianfalleiro/vitess";

// Create the Vitess client
const client = new VtGate({
  baseUrl: "http://localhost:15991",
});

// Create an abort controller to stop the stream when needed
const controller = new AbortController();

// Stream query results
const stream = client.streamExecute(
  {
    query: {
      sql: "SELECT * FROM customer LIMIT 100",
    },
  },
  { controller }
);

// Process the stream
for await (const response of stream) {
  if (response.row) {
    console.log("Row:", response.row);
  }
}

// To kill/close the connection at any time:
controller.abort();

Transactions

import { VtGate, createBindVariable } from "@adrianfalleiro/vitess";

// Create the Vitess client
const client = new VtGate({
  baseUrl: "http://localhost:15991",
});

// Start a transaction
const beginResult = await client.execute({
  query: {
    sql: "BEGIN",
  },
});

// Get the session from the result (contains transaction state)
const session = beginResult.session;

try {
  // Execute statement in transaction
  const result1 = await client.execute({
    session, // Pass the session to continue the transaction
    query: {
      sql: "INSERT INTO customer (name, email) VALUES (:name, :email)",
      bindVariables: {
        name: createBindVariable("John Doe"),
        email: createBindVariable("[email protected]"),
      },
    },
  });

  // Execute another statement in the same transaction
  const result2 = await client.execute({
    session: result1.session, // Use the updated session from previous query
    query: {
      sql: "SELECT * FROM customer WHERE email = :email",
      bindVariables: {
        email: createBindVariable("[email protected]"),
      },
    },
  });

  // Commit the transaction
  await client.execute({
    session: result2.session,
    query: {
      sql: "COMMIT",
    },
  });
} catch (error) {
  // Rollback on error
  await client.execute({
    session,
    query: {
      sql: "ROLLBACK",
    },
  });
}

Using VStream for Change Data Capture

import { VtGate } from "@adrianfalleiro/vitess";

const vtgate = new VtGate({
  baseUrl: "http://localhost:15991",
});

// Create an abort controller to stop the stream when needed
const controller = new AbortController();

// Start the VStream
const vs = vtgate.vStream(
  {
    tabletType: "REPLICA",
    vgtid: {
      shardGtids: [
        {
          keyspace: "commerce",
          shard: "",
          tablePKs: [],
        },
      ],
    },
  },
  { controller }
);

// Stop the listener after 15 seconds
setTimeout(() => controller.abort(), 15_000);

// Process the stream events
for await (const { changes, lastVGtid } of vs) {
  console.log("changes", changes);
  console.log("lastVGtid", lastVGtid);
}

Development

Project Structure

vitess-node/
├── src/             # Source code
│   ├── gen/         # Generated Protocol Buffer code
│   ├── lib/         # Core library
│   └── index.ts     # Main exports
├── proto/           # Protocol Buffer definitions
├── test/            # Tests
└── example/         # Example applications

Running Tests

# Run all tests
npm run test

Building the Project

# Generate Protocol Buffer code
npm run generate

# Format protobuf files
npm run format

# Lint protobuf files
npm run lint

Requirements

  • Node.js 20 or higher
  • Vitess server running and accessible

License

MIT - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.