|
| 1 | +//! # libsql-js |
| 2 | +//! |
| 3 | +//! A wrapper around the libSQL library for use in Node, Bun, and Deno. |
| 4 | +//! |
| 5 | +//! ## Design |
| 6 | +//! |
| 7 | +//! The JavaScript API is designed to be a drop-in replacement for `better-sqlite3` |
| 8 | +//! with an opt-in async variant of the API. |
| 9 | +//! |
| 10 | +//! The JavaScript API has two main classes: `Database` and `Statement`. The `Database` |
| 11 | +//! class is a wrapper around libSQL `Database` and `Connection` structs whereas the |
| 12 | +//! `Statement` class is a wrapper around libSQL `Statement` struct. |
| 13 | +
|
1 | 14 | #![deny(clippy::all)] |
2 | 15 | #![allow(non_snake_case)] |
3 | 16 | #![allow(deprecated)] |
4 | 17 |
|
5 | 18 | mod auth; |
6 | 19 |
|
7 | | -#[macro_use] |
8 | | -extern crate napi_derive; |
9 | | - |
10 | | -use napi::bindgen_prelude::{Array, FromNapiValue, ToNapiValue}; |
11 | | -use napi::{Env, JsUnknown, Result, ValueType}; |
| 20 | +use napi::{ |
| 21 | + bindgen_prelude::{Array, FromNapiValue, ToNapiValue}, |
| 22 | + Env, JsUnknown, Result, ValueType, |
| 23 | +}; |
| 24 | +use napi_derive::napi; |
12 | 25 | use once_cell::sync::OnceCell; |
13 | | -use std::str::FromStr; |
14 | | -use std::sync::atomic::{AtomicBool, Ordering}; |
15 | | -use std::sync::Arc; |
16 | | -use std::time::Duration; |
| 26 | +use std::{ |
| 27 | + str::FromStr, |
| 28 | + sync::{ |
| 29 | + atomic::{AtomicBool, Ordering}, |
| 30 | + Arc, |
| 31 | + }, |
| 32 | + time::Duration, |
| 33 | +}; |
17 | 34 | use tokio::{runtime::Runtime, sync::Mutex}; |
18 | 35 | use tracing_subscriber::{filter::LevelFilter, EnvFilter}; |
19 | 36 |
|
| 37 | +/// SQLite error object. |
20 | 38 | #[napi] |
21 | 39 | pub struct SqliteError { |
22 | 40 | #[napi] |
@@ -47,7 +65,15 @@ impl From<Error> for napi::Error { |
47 | 65 | throw_sqlite_error(msg.clone(), code, *raw_code) |
48 | 66 | } |
49 | 67 | } |
50 | | - _ => todo!(), |
| 68 | + _ => { |
| 69 | + let err_json = serde_json::json!({ |
| 70 | + "message": msg.clone(), |
| 71 | + "libsqlError": true, |
| 72 | + "code": code, |
| 73 | + "rawCode": *raw_code |
| 74 | + }); |
| 75 | + napi::Error::from_reason(err_json.to_string()) |
| 76 | + } |
51 | 77 | } |
52 | 78 | } |
53 | 79 | } |
|
0 commit comments