@zerva/sqlite
TypeScript icon, indicating that this package has built-in type declarations

0.64.0 • Public • Published

🌱 Zerva useSqliteDatabase

This is a side project of Zerva

SQLite abstraction

Installation

npm install @zerva/sqlite

Help

Use better-sqlite3 through a simplified abstraction layer.

A principle followed here to keep life easy with databases is: Never delete something, in particular no columns!

import { useSqliteDatabase } from '@zerva/sqlite'

// Open / create the database
const db = useSqliteDatabase('test.sqlite')

// Get typed results
interface Person {
  id: number
  name: string
  age: number
}

// Create table only if not exists
// Colums that did not exist before are added
// Colums that are not defined but did exist remain untouched
const table = db.table<Person>('person', {
  name: 'text',
  age: 'integer',
})

// Create index, if not existed before
table.index('name')

// Insert
table.insert({
  name: 'Doe',
  age: 49,
})

// Get all rows
const allRows = table.all()

// Get one row
const doe = table.get(1)

// Directly do all you like do with BetterSQLite3
const betterSQLiteDatabase = db.db

Visual Database Design

Support for DrawDB planned.

Links

Inspirations and alternatives:

Readme

Keywords

none

Package Sidebar

Install

npm i @zerva/sqlite

Weekly Downloads

4

Version

0.64.0

License

MIT

Unpacked Size

128 kB

Total Files

9

Last publish

Collaborators

  • zerva