Rename ConnectionFlags to OpenFlags

This commit is contained in:
Ivan Ukhov 2019-06-09 07:15:34 +02:00
parent d1e9f8fd3e
commit 039bf4c67e
3 changed files with 12 additions and 15 deletions

View File

@ -14,18 +14,18 @@ pub struct Connection {
/// A set of connection flags.
#[derive(Clone, Copy, Debug)]
pub struct ConnectionFlags(c_int);
pub struct OpenFlags(c_int);
unsafe impl Send for Connection {}
impl Connection {
/// Open a read-write connection to a new or existing database.
pub fn open<T: AsRef<Path>>(path: T) -> Result<Connection> {
Connection::open_with_flags(path, ConnectionFlags::new().set_create().set_read_write())
Connection::open_with_flags(path, OpenFlags::new().set_create().set_read_write())
}
/// Open a database connection with a specific set of connection flags.
pub fn open_with_flags<T: AsRef<Path>>(path: T, flags: ConnectionFlags) -> Result<Connection> {
/// Open a database connection with a specific set of flags.
pub fn open_with_flags<T: AsRef<Path>>(path: T, flags: OpenFlags) -> Result<Connection> {
let mut raw = 0 as *mut _;
unsafe {
ok!(ffi::sqlite3_open_v2(
@ -157,11 +157,11 @@ impl Drop for Connection {
}
}
impl ConnectionFlags {
impl OpenFlags {
/// Create a set of connection flags.
#[inline]
pub fn new() -> Self {
ConnectionFlags(0)
OpenFlags(0)
}
/// Create the database if it does not already exist.

View File

@ -294,7 +294,7 @@ mod cursor;
mod statement;
pub use connection::Connection;
pub use connection::ConnectionFlags;
pub use connection::OpenFlags;
pub use cursor::Cursor;
pub use statement::{Bindable, Readable, State, Statement};
@ -304,12 +304,9 @@ pub fn open<T: AsRef<std::path::Path>>(path: T) -> Result<Connection> {
Connection::open(path)
}
/// Open a connection to a database with a specific set of connection flags.
/// Open a connection to a database with a specific set of flags.
#[inline]
pub fn open_with_flags<T: AsRef<std::path::Path>>(
path: T,
flags: ConnectionFlags,
) -> Result<Connection> {
pub fn open_with_flags<T: AsRef<std::path::Path>>(path: T, flags: OpenFlags) -> Result<Connection> {
Connection::open_with_flags(path, flags)
}

View File

@ -1,7 +1,7 @@
extern crate sqlite;
extern crate temporary;
use sqlite::{Connection, ConnectionFlags, State, Type, Value};
use sqlite::{Connection, OpenFlags, State, Type, Value};
use std::path::Path;
macro_rules! ok(($result:expr) => ($result.unwrap()));
@ -48,10 +48,10 @@ fn connection_open_with_flags() {
let path = directory.path().join("database.sqlite3");
setup_users(&path);
let flags = ConnectionFlags::new().set_read_only();
let flags = OpenFlags::new().set_read_only();
let connection = ok!(sqlite::open_with_flags(path, flags));
match connection.execute("INSERT INTO users VALUES (2, 'Bob', NULL, NULL)") {
Err(_) => {},
Err(_) => {}
_ => unreachable!(),
}
}