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

adasql

v1.2.0

Published

CLI SQL client for AWS Aurora Data API Databases

Downloads

9

Readme

AWS Aurora Data API SQL client

This Node.js package provides a CLI client to connect and query AWS Aurora Database Clusters using the Data API. It mimics the mysql and psql CLI clients.

Usage

First, create an Aurora Serverless Database (here's a blog post with an example).

Next install this package:

$ npm install --global adasql

Now run the command:

$ adasql -d testdb
Using AWS Credentials: From local environment
Using AWS Region: From local environment
AWS Account: 012345678901
AWS Region: us-west-2
AWS User: assumed-role/[email protected]/cli
AWS Account Alias: (none)
Found only one Aurora Data API-enabled Database Cluster: mystack-mydb-s98d7f8d7f
Found only one secret in AWS Secrets Manager: /mystack/mydb/user-secret
Connecting with the following configuration: 
  RDS Aurora Cluster ID:       mystack-mydb-s98d7f8d7f
  Secrets Manager Secret Name: /mystack/mydb/user-secret
  Database:                    testdb
> SELECT * FROM feature_flags;
Records: 
  - 
    id:              1
    feature_name:    myAwesomeNewFeature
Record Count: 1

adasql will show you information up top to help you ensure you're connecting to the right DB. It will then look for AWS Aurora Database Clusters with the Data API enabled. If it finds only one database cluster it will use it, otherwise it will prompt you for the database to connect to. It will then look for AWS Secrets Manager Secrets to use for authentication when connecting. Again, if it finds only one secret it will use it, otherwise it will prompt you for the secret to use.

Transactions are supported, though note the Data API doesn't support save points or nested transactions.

Multiple statements and multi-line statements

SQL statements are executed sequentially, and multiple statements can be executed when separated with the ';' delimiter. For example, the following query when executed will insert a new record and then return the same record as the first statement executes to completion before the second statement is executed:

INSERT INTO people (id, name, age) VALUES (1, 'Alice', 39); SELECT * from mytable WHERE id = 1;

Canceling commands

If you find yourself in the middle of a multi-line statement and wish to cancel it, enter .clear. This will reset the state of the REPL, though it will not affect a transaction if it is in progress.

FAQ

Can adasql be used for migrations, seeding data, or restoring backups?

Maybe! But for most use cases adasql will not work. The Aurora Data API has three issues that make migrations and restoring backups difficult:

  • SQL connections to the DB used by the Data API are multiplexed, and there is no way to ensure affinity for statements that set per-connection variables. This is important when restoring backups where the backups need to execute commands like SET FOREIGN_KEY_CHECKS=0 to disable foreign key checks when inserting records using the same connection. Multiple statements that need to be executed on the same connection with these connection-specific variables will likely fail part-way through execution.
  • SQL statements larger than 64 KB are not supported. If you want to insert a batch of records, make sure they are separated into chunks of statements smaller than 64 KB.
  • SQL statements that take longer than 45 seconds to complete will timeout. The adasql client does not tell the Data API to continue these statements if they do timeout for data integrity purposes. But, DDL statements that timeout may cause non-reversible changes when canceled.

Your use case may not hit these limitations, in which case have at it! But many use cases will, especially the first and second limitations when attempting to restore a mysqldump backup. You may find you can work around the limitations by:

  1. Running mysqldump with the --extended-insert=FALSE argument to insert every record using a separate statement to keep statements under 64 KB in size
  2. If your tables have foreign key constraints, you may be able to re-order them with children tables and records first, then parent tables and records second, allowing you to create tables and insert records without violating the constraints