w1-sqliter

2.0.1 • Public • Published

W1 Sqliter

This is a small wrapper for easy use of the sqlite 3 database.

How to use

Install

npm install w1-sqliter

Example usage

import sqliter from 'w1-sqliter'
import path from 'path'
import { dirname } from 'path'
import { fileURLToPath } from 'url'

const dbFilePath = path.resolve(dirname(fileURLToPath(import.meta.url)), 'test.db')

main()

async function main() {
    const db = new sqliter()
    await db.init(dbFilePath)

    // create table if not exists with auto increment primary key
    await db.run('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)')

    await db.run('INSERT INTO test (name) VALUES (?)', ['John Doey'])

    const rows = await db.all('SELECT * FROM test')
    console.log(rows)
}

Readme

Keywords

none

Package Sidebar

Install

npm i w1-sqliter

Weekly Downloads

1

Version

2.0.1

License

ISC

Unpacked Size

5.29 kB

Total Files

5

Last publish

Collaborators

  • nw1n