Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@neondatabase/serverless

Package Overview
Dependencies
Maintainers
6
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@neondatabase/serverless

node-postgres for serverless environments from neon.tech

  • 0.10.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
204K
increased by2.53%
Maintainers
6
Weekly downloads
 
Created

What is @neondatabase/serverless?

@neondatabase/serverless is an npm package designed to facilitate serverless interactions with Neon, a serverless PostgreSQL database. It provides a set of tools and utilities to connect, query, and manage PostgreSQL databases in a serverless environment, making it easier to build scalable and efficient applications.

What are @neondatabase/serverless's main functionalities?

Connecting to a Neon Database

This feature allows you to establish a connection to a Neon database using the provided connection string. The code sample demonstrates how to create a new client instance and connect to the database.

const { Client } = require('@neondatabase/serverless');

const client = new Client({
  connectionString: process.env.NEON_DATABASE_URL,
});

async function connect() {
  await client.connect();
  console.log('Connected to Neon Database');
}

connect();

Executing SQL Queries

This feature allows you to execute SQL queries against the connected Neon database. The code sample demonstrates how to connect to the database, execute a SELECT query, and log the results.

const { Client } = require('@neondatabase/serverless');

const client = new Client({
  connectionString: process.env.NEON_DATABASE_URL,
});

async function executeQuery() {
  await client.connect();
  const res = await client.query('SELECT * FROM users');
  console.log(res.rows);
  await client.end();
}

executeQuery();

Handling Transactions

This feature allows you to handle transactions in the Neon database. The code sample demonstrates how to begin a transaction, execute an insert query, commit the transaction, and handle errors by rolling back the transaction if necessary.

const { Client } = require('@neondatabase/serverless');

const client = new Client({
  connectionString: process.env.NEON_DATABASE_URL,
});

async function handleTransaction() {
  await client.connect();
  try {
    await client.query('BEGIN');
    await client.query('INSERT INTO users(name) VALUES($1)', ['John Doe']);
    await client.query('COMMIT');
    console.log('Transaction committed');
  } catch (e) {
    await client.query('ROLLBACK');
    console.error('Transaction rolled back', e);
  } finally {
    await client.end();
  }
}

handleTransaction();

Other packages similar to @neondatabase/serverless

Keywords

FAQs

Package last updated on 06 Nov 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc