Skip to main content

post_archiver/importer/
platform.rs

1use crate::{
2    error::Result,
3    manager::{PostArchiverConnection, PostArchiverManager},
4    PlatformId,
5};
6
7impl<T> PostArchiverManager<T>
8where
9    T: PostArchiverConnection,
10{
11    /// Import a platform into the archive.
12    ///
13    /// If the platform already exists, it returns the existing ID.
14    ///
15    /// # Errors
16    ///
17    /// Returns `Error` if there was an error accessing the database.
18    pub fn import_platform(&self, platform: String) -> Result<PlatformId> {
19        // find
20        if let Some(id) = self.find_platform(&platform)? {
21            return Ok(id);
22        }
23
24        // insert
25        let mut stmt = self
26            .conn()
27            .prepare_cached("INSERT INTO platforms (name) VALUES (?) RETURNING id")?;
28        Ok(stmt.query_row([&platform], |row| row.get(0))?)
29    }
30}