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

@types/better-sqlite3

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/better-sqlite3

TypeScript definitions for better-sqlite3

  • 7.6.12
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
242K
increased by11.85%
Maintainers
1
Weekly downloads
 
Created

What is @types/better-sqlite3?

@types/better-sqlite3 provides TypeScript type definitions for the better-sqlite3 package, which is a fast and simple SQLite3 library for Node.js applications. It allows for synchronous database operations and provides a straightforward API for executing SQL queries, managing transactions, and handling prepared statements.

What are @types/better-sqlite3's main functionalities?

Executing SQL Queries

This feature allows you to execute SQL queries synchronously. The code sample demonstrates how to prepare and execute a SELECT query to fetch a user with a specific ID.

const Database = require('better-sqlite3');
const db = new Database('my-database.db');
const row = db.prepare('SELECT * FROM users WHERE id = ?').get(1);
console.log(row);

Managing Transactions

This feature allows you to manage transactions, ensuring that a series of database operations are executed atomically. The code sample demonstrates how to create and execute a transaction that inserts multiple users into the database.

const Database = require('better-sqlite3');
const db = new Database('my-database.db');
const insert = db.prepare('INSERT INTO users (name, age) VALUES (?, ?)');
const transaction = db.transaction((users) => {
  for (const user of users) insert.run(user.name, user.age);
});
transaction([{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);

Handling Prepared Statements

This feature allows you to handle prepared statements for executing SQL queries multiple times with different parameters. The code sample demonstrates how to prepare an INSERT statement and execute it with different values.

const Database = require('better-sqlite3');
const db = new Database('my-database.db');
const stmt = db.prepare('INSERT INTO users (name, age) VALUES (?, ?)');
stmt.run('Charlie', 35);
stmt.run('Dave', 40);

Other packages similar to @types/better-sqlite3

FAQs

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