qpdb / mentat

A persistent, relational store inspired by Datomic and DataScript.
https://mentat.rs/
Apache License 2.0
52 stars 2 forks source link

Implement exporting (and importing) #194

Open gburd opened 4 years ago

gburd commented 4 years ago

With a small amount of work we can extract Tolstoy's tx_processor, moving it into db and wrapping it in conn.rs.

The signature might look something like this:

impl<'a, 'c> InProgress<'a, 'c> {
    /// Write out the contents of the store in a way that can be loaded.
    /// There are two ways to do this:
    ///
    /// - Preserving identifiers. Loading onto a non-empty store is likely to fail.
    ///   Loading into the existing store should transact nothing.
    /// - Remapping all identifiers to temporary IDs. This is more work to load, and
    ///   repeated loads will result in some duplicated entities, but smushing should
    ///   cause identifiers to be unified.
    ///
    /// The file will be populated with a sequence of transactions, each consisting of
    /// a sequence of datoms.
    fn export(&self, file: File) -> Result<File> {
        …
    }
}

impl<'a, 'c> InProgressRead<'a, 'c> {
    fn export(&self, file: File) -> Result<File> {
        self.inner.export(file)
    }
}

impl Conn {
    fn export(&self, file: File) -> Result<File> {
        self.begin_read()?.export(file)
    }
}

impl Store {
    fn export(&self, file: File) -> Result<File> {
        self.conn.export(file)
    }
}

That block comment is one way this could work.