Coder Social home page Coder Social logo

heng1025 / deno-sqlite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dyedgreen/deno-sqlite

1.0 1.0 0.0 28.17 MB

Deno SQLite module

Home Page: https://deno.land/x/sqlite

License: MIT License

JavaScript 8.12% C 19.39% TypeScript 69.06% Makefile 3.43%

deno-sqlite's Introduction

Deno SQLite Module

test status deno doc

This is an SQLite module for JavaScript and TypeScript. The wrapper is targeted at Deno and uses a version of SQLite3 compiled to WebAssembly (WASM). This module focuses on correctness, ease of use and performance.

This module guarantees API compatibility according to semantic versioning. Please report any issues you encounter. Note that the master branch might contain new or breaking features. The versioning guarantee applies only to tagged releases.

Documentation

Documentation is available Deno Docs. There is also a list of examples in the examples folder.

Example

import { DB } from "https://deno.land/x/sqlite/mod.ts";

// Open a database
const db = new DB("test.db");
db.execute(`
  CREATE TABLE IF NOT EXISTS people (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
  )
`);

// Run a simple query
for (const name of ["Peter Parker", "Clark Kent", "Bruce Wayne"]) {
  db.query("INSERT INTO people (name) VALUES (?)", [name]);
}

// Print out data in table
for (const [name] of db.query("SELECT name FROM people")) {
  console.log(name);
}

// Close connection
db.close();

Comparison to Plugin based Modules

TL;DR

If you want something that just works (and is fast), use this library.

Depending on your specific needs, there is also sqlite3, however using this module requires the --allow-ffi and --unstable flags, which means the database connection may bypass e.g. file access permissions.

Advantages

  • Security: benefit from Denos security settings, without the need to trust a third party
  • Portability: runs everywhere Deno runs and can even run in the browser
  • Ease of Use: takes full advantage of Denos module cache and does not require any network access after initial download
  • Speed: thanks to WASM, the database performance is comparable to native bindings in most situations and the API is carefully designed to provide optimal performance

Disadvantages

  • Weaker Persistence Guarantees: due to limitations in Denos file system APIs, SQLite can't acquire file locks or memory map files (e.g. this module does not support WAL mode)

Browser Version (Experimental)

There is experimental support for using deno-sqlite in the browser. You can generate a browser compatible module by running:

deno bundle --import-map browser/import_map.json browser/mod.ts [output_bundle_path]

The modules documentation can be seen by running

deno doc browser/mod.ts

Databases created in the browser are persisted using indexedDB.

Users

(listed in alphabetical order, please submit a PR if you are using this library and are not included)

deno-sqlite's People

Contributors

anttirae avatar dyedgreen avatar halvardssm avatar hsjoberg avatar jeremybanks avatar jsejcksn avatar patrickpang avatar rahmanfadhil avatar rherrmann avatar uki00a avatar waynebloss avatar wirelyre avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.