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

@medishn/gland-qiu

v2.1.2

Published

A query runner for SQL

Downloads

16

Readme

@medishn/gland-qiu

NPM Version License

@medishn/gland-qiu is a flexible and efficient database management tool that handles multiple SQL databases with powerful caching, rate-limiting, and task management functionalities for database operations.

Features

  • Multi-database Support: Supports various SQL databases through a flexible configuration.
  • Rate Limiting: Ensures controlled execution of tasks with custom rate-limits.
  • Task Management: Queue-based task execution system for managing multiple queries.
  • Cache Management: In-memory caching system to reuse frequently used commands and reduce overhead.
  • File-based Query Execution: Supports SQL queries from .sql files.

Installation

Install the package using npm:

npm install @medishn/gland-qiu

Getting Started

Below is an example of how to use the Qiu class to run database queries:

Initialization

To begin using Qiu, you need to initialize it with your database type and connection string.

import { Qiu } from "@medishn/gland-qiu";

const db = new Qiu({
  type: "postgresql",
  connect: "psql -U postgres -d postgres -h localhost -p 5432",
});

You can also specify MySQL or MariaDB:

const db = new Qiu({
  type: "mysql",
  connect: "mysql://username:password@localhost:3306/mydatabase",
});

Execute a Query

Simple Query

To execute a simple SQL query, use the exec method.

await db.exec("SELECT * FROM users;");

File-based Query

You can also run SQL queries stored in .sql files:

await db.exec("queries/init.sql", { isFile: true });

Get Output from the Query

If you want the result of the query, set the value option to true.

const result = await db.exec("SELECT * FROM users;", { value: true });
console.log(result);

API Reference

Qiu

constructor(config: { connect: string, type: DatabaseSqlType })

  • config: An object containing:
    • connect: The connection string or URI of the database.
    • type: The type of database.

exec(query: string, options?: { value?: boolean, isFile?: boolean }): Promise<void | string>

  • query: The SQL query string or path to the .sql file.
  • options: (Optional) If value is set to true, the result of the query will be returned. If isFile is set to true, the query will be treated as a file path.

Example

import { Qiu } from "@medishn/gland-qiu";

const db = new Qiu({
  type: "postgresql",
  connect: "psql -U postgres -d test_qiu -h localhost -p 5432",
});

await db.exec("init.sql", { isFile: true });
const result = await db.exec("SELECT * FROM users;", { value: true });
console.log(result);

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md file for more information.

Changelog

Details about the latest changes are documented in CHANGELOG.md.

Security

If you find any security-related issues, please report them to [email protected].

License

This project is licensed under the MIT License. See the LICENSE file for details.