Socket
Book a DemoInstallSign in
Socket

@planetscale/database

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planetscale/database

A Fetch API-compatible PlanetScale database driver

latest
Source
npmnpm
Version
1.19.0
Version published
Weekly downloads
227K
49.3%
Maintainers
6
Weekly downloads
 
Created

What is @planetscale/database?

@planetscale/database is an npm package designed to facilitate interaction with PlanetScale databases. It provides a simple and efficient way to connect to, query, and manage databases hosted on PlanetScale, which is a serverless MySQL platform.

What are @planetscale/database's main functionalities?

Connecting to a Database

This feature allows you to establish a connection to a PlanetScale database using the provided credentials. The `connect` function is used to create a connection object that can be used for executing queries.

const { connect } = require('@planetscale/database');

const connection = connect({
  host: 'your-database-host',
  username: 'your-username',
  password: 'your-password'
});

Executing Queries

This feature demonstrates how to execute SQL queries against a PlanetScale database. The `execute` method is used to run a query and retrieve results, which can then be processed or logged.

const { connect } = require('@planetscale/database');

const connection = connect({
  host: 'your-database-host',
  username: 'your-username',
  password: 'your-password'
});

async function fetchData() {
  const results = await connection.execute('SELECT * FROM your_table');
  console.log(results);
}

fetchData();

Handling Transactions

This feature illustrates how to handle transactions using the @planetscale/database package. Transactions allow you to execute a series of operations atomically, ensuring that either all operations succeed or none are applied.

const { connect } = require('@planetscale/database');

const connection = connect({
  host: 'your-database-host',
  username: 'your-username',
  password: 'your-password'
});

async function performTransaction() {
  const transaction = await connection.transaction();
  try {
    await transaction.execute('INSERT INTO your_table (column) VALUES (value)');
    await transaction.commit();
  } catch (error) {
    await transaction.rollback();
    console.error('Transaction failed:', error);
  }
}

performTransaction();

Other packages similar to @planetscale/database

Keywords

planetscale

FAQs

Package last updated on 14 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.