1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::*;

use rusqlite::*;
use std::path::Path;

impl SqliteAnimation {
    ///
    /// Creates a new in-memory animation
    /// 
    pub fn new_in_memory() -> SqliteAnimation {
        let db = AnimationDb::new();

        SqliteAnimation {
            db: db
        }
    }

    ///
    /// Creates an animation in a file
    /// 
    pub fn new_with_file<P: AsRef<Path>>(path: P) -> Result<SqliteAnimation> {
        let db = AnimationDb::new_from_connection(Connection::open_with_flags(path, SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE)?);

        Ok(SqliteAnimation {
            db: db
        })
    }

    ///
    /// Takes an existing SQLite connection and creates a new animation in it
    /// 
    pub fn set_up_existing_database(sqlite: Connection) -> Result<SqliteAnimation> {
        let db = AnimationDb::new_from_connection(sqlite);
        Ok(SqliteAnimation {
            db: db
        })
    }

    ///
    /// Uses an existing SQLite connection with an animation in it to create an animation object
    /// 
    pub fn from_existing_database(sqlite: Connection) -> Result<SqliteAnimation> {
        let db = AnimationDb::from_connection(sqlite);
        Ok(SqliteAnimation {
            db: db
        })
    }
}