checkpoint

This commit is contained in:
Oliver 2025-07-10 18:46:25 -06:00
parent 6fc71c7a78
commit 4989a59ddf
3 changed files with 52 additions and 2282 deletions

2287
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,8 @@ metrics-exporter-prometheus = { version = "0.16.2", features=["http-listener"]}
# minio = "0.1.0" # minio = "0.1.0"
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"} minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}
reqwest = { version = "0.12", features = ["gzip", "default", "rustls-tls"] } reqwest = { version = "0.12", features = ["gzip", "default", "rustls-tls"] }
rusqlite = { version = "0.34.0", features = ["bundled"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
surrealdb = "2.2"
tokio = { version="1.41.0", features = ["full"] } tokio = { version="1.41.0", features = ["full"] }
toml = "0.8.20" toml = "0.8.20"
tracing = "0.1" tracing = "0.1"

View File

@ -1,12 +1,7 @@
use metrics::counter; use metrics::counter;
use rusqlite::Connection;
use std::fmt::Debug; use std::fmt::Debug;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use surrealdb::{
engine::remote::ws::{Client, Ws},
opt::auth::Root,
sql::Thing,
Surreal,
};
use tracing::{error, instrument, trace}; use tracing::{error, instrument, trace};
use url::Url; use url::Url;
@ -49,10 +44,16 @@ impl Website {
// Insert ever item in the vec into surreal, crawled state will be preserved as TRUE // Insert ever item in the vec into surreal, crawled state will be preserved as TRUE
// if already in the database as such or incoming data is TRUE. // if already in the database as such or incoming data is TRUE.
pub async fn store_all(all: Vec<Self>, db: &Surreal<Client>) -> Vec<Thing> { pub async fn store_all(all: Vec<Self>, db: &Connection) {
counter!(STORE).increment(1); counter!(STORE).increment(1);
let mut things = Vec::with_capacity(all.len()); let mut things = Vec::with_capacity(all.len());
rusqlite::ParamsFromIter;
db.execute("",
params![]
);
match db match db
.query( .query(
"INSERT INTO website $array "INSERT INTO website $array
@ -89,32 +90,10 @@ pub struct Record {
pub id: Thing, pub id: Thing,
} }
#[instrument(skip_all, name = "SurrealDB")] #[instrument(skip_all, name = "sqlite_connect")]
pub async fn connect(config: &Config) -> surrealdb::Result<Surreal<Client>> { pub async fn connect(config: &Config) -> Result<Connection, rusqlite::Error> {
trace!("Establishing connection to surreal..."); trace!("Establishing connection to sqlite...");
// Connect to the server // Connect to the server
let db = Surreal::new::<Ws>(&config.surreal_url).await?; Connection::open("./squeelite.db")
trace!("Logging in...");
// Signin as a namespace, database, or root user
db.signin(Root {
username: &config.surreal_username,
password: &config.surreal_password,
})
.await?;
// Select a specific namespace / database
db.use_ns(&config.surreal_ns)
.use_db(&config.surreal_db)
.await?;
let setup = include_bytes!("setup.surql");
let file = setup.iter().map(|c| *c as char).collect::<String>();
db.query(file)
.await
.expect("Failed to setup surreal tables.");
Ok(db)
} }