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

View File

@ -294,7 +294,7 @@ mod cursor;
mod statement; mod statement;
pub use connection::Connection; pub use connection::Connection;
pub use connection::ConnectionFlags; pub use connection::OpenFlags;
pub use cursor::Cursor; pub use cursor::Cursor;
pub use statement::{Bindable, Readable, State, Statement}; 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) 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] #[inline]
pub fn open_with_flags<T: AsRef<std::path::Path>>( pub fn open_with_flags<T: AsRef<std::path::Path>>(path: T, flags: OpenFlags) -> Result<Connection> {
path: T,
flags: ConnectionFlags,
) -> Result<Connection> {
Connection::open_with_flags(path, flags) Connection::open_with_flags(path, flags)
} }

View File

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