Skip to content

Commit 267de97

Browse files
committed
HACKS
1 parent 701cdba commit 267de97

2 files changed

Lines changed: 1164 additions & 1383 deletions

File tree

src/lib.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
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+
114
#![deny(clippy::all)]
215
#![allow(non_snake_case)]
316
#![allow(deprecated)]
417

518
mod auth;
619

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;
1225
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+
};
1734
use tokio::{runtime::Runtime, sync::Mutex};
1835
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
1936

37+
/// SQLite error object.
2038
#[napi]
2139
pub struct SqliteError {
2240
#[napi]
@@ -47,7 +65,15 @@ impl From<Error> for napi::Error {
4765
throw_sqlite_error(msg.clone(), code, *raw_code)
4866
}
4967
}
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+
}
5177
}
5278
}
5379
}

0 commit comments

Comments
 (0)