Add InProgress.import to load transaction data from a file. r=emily
It's not streaming, but it'll do.
This commit is contained in:
parent
0ca61017a1
commit
bead9752bd
2 changed files with 17 additions and 0 deletions
16
src/conn.rs
16
src/conn.rs
|
@ -10,6 +10,14 @@
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use std::fs::{
|
||||||
|
File,
|
||||||
|
};
|
||||||
|
|
||||||
|
use std::io::{
|
||||||
|
Read,
|
||||||
|
};
|
||||||
|
|
||||||
use std::path::{
|
use std::path::{
|
||||||
Path,
|
Path,
|
||||||
};
|
};
|
||||||
|
@ -385,6 +393,14 @@ impl<'a, 'c> InProgress<'a, 'c> {
|
||||||
self.transact_entities(entities)
|
self.transact_entities(entities)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn import<P>(&mut self, path: P) -> Result<TxReport>
|
||||||
|
where P: AsRef<Path> {
|
||||||
|
let mut file = File::open(path)?;
|
||||||
|
let mut text: String = String::new();
|
||||||
|
file.read_to_string(&mut text)?;
|
||||||
|
self.transact(text.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rollback(self) -> Result<()> {
|
pub fn rollback(self) -> Result<()> {
|
||||||
self.transaction.rollback().map_err(|e| e.into())
|
self.transaction.rollback().map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ error_chain! {
|
||||||
EdnParseError(edn::ParseError);
|
EdnParseError(edn::ParseError);
|
||||||
Rusqlite(rusqlite::Error);
|
Rusqlite(rusqlite::Error);
|
||||||
UuidParseError(uuid::ParseError);
|
UuidParseError(uuid::ParseError);
|
||||||
|
IoError(::std::io::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
links {
|
links {
|
||||||
|
|
Loading…
Reference in a new issue