feat: impl get_forge for sqlx sqlite
This commit is contained in:
parent
7b343a2cd5
commit
6fb71e0641
2 changed files with 69 additions and 0 deletions
|
@ -196,6 +196,36 @@
|
||||||
},
|
},
|
||||||
"query": "INSERT INTO\n starchart_forges (hostname, verified_on, forge_type ) \n VALUES ($1, $2, (SELECT ID FROM starchart_forge_type WHERE name = $3))"
|
"query": "INSERT INTO\n starchart_forges (hostname, verified_on, forge_type ) \n VALUES ($1, $2, (SELECT ID FROM starchart_forge_type WHERE name = $3))"
|
||||||
},
|
},
|
||||||
|
"a4e02e0fafe95a6e21347607f5f69a06f592c3624775feadaaf5fa5b4285815d": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "hostname",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "last_crawl_on",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "SELECT \n\t\thostname,\n\t\tlast_crawl_on,\n\t\tstarchart_forge_type.name\n FROM\n starchart_forges\n INNER JOIN\n starchart_forge_type\n ON\n starchart_forges.forge_type = starchart_forge_type.id\n WHERE\n hostname = $1;\n "
|
||||||
|
},
|
||||||
"a75419ce6d1248944a7bdd63ddadd6f1017a27b8490fb2746a0f7a5d35ce889a": {
|
"a75419ce6d1248944a7bdd63ddadd6f1017a27b8490fb2746a0f7a5d35ce889a": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use db_core::dev::*;
|
use db_core::dev::*;
|
||||||
|
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
@ -140,6 +142,43 @@ impl SCDatabase for Database {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get forge isntance data
|
||||||
|
async fn get_forge(&self, hostname: &str) -> DBResult<Forge> {
|
||||||
|
struct InnerForge {
|
||||||
|
hostname: String,
|
||||||
|
last_crawl_on: Option<i64>,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
let f = sqlx::query_as!(
|
||||||
|
InnerForge,
|
||||||
|
"SELECT
|
||||||
|
hostname,
|
||||||
|
last_crawl_on,
|
||||||
|
starchart_forge_type.name
|
||||||
|
FROM
|
||||||
|
starchart_forges
|
||||||
|
INNER JOIN
|
||||||
|
starchart_forge_type
|
||||||
|
ON
|
||||||
|
starchart_forges.forge_type = starchart_forge_type.id
|
||||||
|
WHERE
|
||||||
|
hostname = $1;
|
||||||
|
",
|
||||||
|
hostname,
|
||||||
|
)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DBError::DBError(Box::new(e)))?;
|
||||||
|
|
||||||
|
let f = Forge {
|
||||||
|
hostname: f.hostname,
|
||||||
|
last_crawl_on: f.last_crawl_on,
|
||||||
|
forge_type: ForgeImplementation::from_str(&f.name).unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(f)
|
||||||
|
}
|
||||||
|
|
||||||
/// check if a forge instance exists
|
/// check if a forge instance exists
|
||||||
async fn forge_exists(&self, hostname: &str) -> DBResult<bool> {
|
async fn forge_exists(&self, hostname: &str) -> DBResult<bool> {
|
||||||
match sqlx::query!(
|
match sqlx::query!(
|
||||||
|
|
Loading…
Reference in a new issue