Skip to content

feat(ext/node): (partial) impl sqlite 'backup' function #29842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edilson258
Copy link
Contributor

Towards #29439

This PR aims to implement the node:sqlite backup function

pub async fn op_backup_db(
state: Rc<RefCell<OpState>>,
) -> Result<i64, SqliteError> {
Ok(69)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@edilson258
Copy link
Contributor Author

Hi @littledivy

I'm trying to impl. the node:sqlite backup function.

Deno uses rusqlite lib under the hoods and it provides a backup function, so i decided to wrap it in an op and expose it to the js land

function provided by rusqlite

fn backup_db<P: AsRef<Path>>(
  src: &rusqlite::Connection,
  dst: P,
  progress: fn(rusqlite::backup::Progress),
 ) -> Result<()> { ... }

Node's backup function signature

async function backup(
  sourceDb: DatabaseSync,
  path: string,
  options?: BackupOptions,
): Promise<void>;

At this point i know that the rusqlite::Connection object needed by the rusqlite backup function is inside of sourceDb but i dont know how to pass it to rust op

@edilson258 edilson258 force-pushed the feat/sqlite-backup branch from ff3a6eb to 829c972 Compare June 22, 2025 15:39
@edilson258 edilson258 marked this pull request as ready for review June 22, 2025 15:40
let src_conn_ref = source_db.conn.borrow();
let src_conn = src_conn_ref.as_ref().ok_or(SqliteError::SessionClosed)?;
let path = std::path::Path::new(&path);
let mut dst_conn = Connection::open(path)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to add write permission checks here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

judging by the signature

function backup(
  sourceDb: DatabaseSync,
  path: string | Buffer | URL,
  options?: BackupOptions,
): Promise<void>;

Since path can have different forms, we'll need to check diff permissions accordingly.

@edilson258
Copy link
Contributor Author

I can't figure how to pass the progress call back function from js land to rust op. is there some code that i can inspire on??

@edilson258 edilson258 force-pushed the feat/sqlite-backup branch from 829c972 to 84457b5 Compare June 23, 2025 16:12
@edilson258 edilson258 force-pushed the feat/sqlite-backup branch from 84457b5 to 16da5ef Compare June 30, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants