Skip to content

Added:Support for read-only databases in the Rust crate.#347

Closed
xonx4l wants to merge 1 commit intotursodatabase:mainfrom
xonx4l:patch-1
Closed

Added:Support for read-only databases in the Rust crate.#347
xonx4l wants to merge 1 commit intotursodatabase:mainfrom
xonx4l:patch-1

Conversation

@xonx4l
Copy link
Contributor

@xonx4l xonx4l commented Sep 1, 2023

issue -:#344

impl Database {
/// Open a local database file.
pub fn open<S: Into<String>>(db_path: S) -> Result<Database> {
pub fn open<S: Into<String>>(db_path: S, readonly:bool) -> Result<Database> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should do a open_with_flags() associate function like Rusqlite does for this instead of adding a boolean to open() that everybody has to pass.

@penberg
Copy link
Collaborator

penberg commented Sep 1, 2023

Hey @xonx4l! Thanks for the pull request! I already commented on the open_with_flags() thing, but another thing that's maybe not as obvious is: please add this to the v2 module in the crates/core. That will soon become the main top-level API.

.map_err(|e| ConnectionFailed(format!("{:?}", e)))
}

pub fn use_database(&self) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like some left-over code.

pub fn connect(&self) -> Result<Connection> {
Connection::connect(self)
if self.readonly {
Connection::open_with_flags(&self.db_path, rusqlite::OpenFlags::SQLITE_RO)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should use libsql-sys and SQLITE_OPEN_READONLY here.

@penberg
Copy link
Collaborator

penberg commented Sep 19, 2023

Implemented in commit befd735.

@penberg penberg closed this Sep 19, 2023
MarinPostma added a commit that referenced this pull request Oct 17, 2023
347: disable temp table creation r=MarinPostma a=MarinPostma

Temp tables cannot be supported for now because they change the state of the connection.


Co-authored-by: ad hoc <postma.marin@protonmail.com>
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.

2 participants