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:
Richard Newman 2018-02-23 10:19:33 -08:00
parent 0ca61017a1
commit bead9752bd
2 changed files with 17 additions and 0 deletions

View file

@ -10,6 +10,14 @@
#![allow(dead_code)]
use std::fs::{
File,
};
use std::io::{
Read,
};
use std::path::{
Path,
};
@ -385,6 +393,14 @@ impl<'a, 'c> InProgress<'a, 'c> {
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<()> {
self.transaction.rollback().map_err(|e| e.into())
}

View file

@ -40,6 +40,7 @@ error_chain! {
EdnParseError(edn::ParseError);
Rusqlite(rusqlite::Error);
UuidParseError(uuid::ParseError);
IoError(::std::io::Error);
}
links {