checkpoint
This commit is contained in:
parent
6fc71c7a78
commit
4989a59ddf
2287
Cargo.lock
generated
2287
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,8 +11,8 @@ metrics-exporter-prometheus = { version = "0.16.2", features=["http-listener"]}
|
||||
# minio = "0.1.0"
|
||||
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}
|
||||
reqwest = { version = "0.12", features = ["gzip", "default", "rustls-tls"] }
|
||||
rusqlite = { version = "0.34.0", features = ["bundled"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
surrealdb = "2.2"
|
||||
tokio = { version="1.41.0", features = ["full"] }
|
||||
toml = "0.8.20"
|
||||
tracing = "0.1"
|
||||
|
45
src/db.rs
45
src/db.rs
@ -1,12 +1,7 @@
|
||||
use metrics::counter;
|
||||
use rusqlite::Connection;
|
||||
use std::fmt::Debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::{
|
||||
engine::remote::ws::{Client, Ws},
|
||||
opt::auth::Root,
|
||||
sql::Thing,
|
||||
Surreal,
|
||||
};
|
||||
use tracing::{error, instrument, trace};
|
||||
use url::Url;
|
||||
|
||||
@ -49,10 +44,16 @@ impl Website {
|
||||
|
||||
// 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.
|
||||
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);
|
||||
let mut things = Vec::with_capacity(all.len());
|
||||
|
||||
rusqlite::ParamsFromIter;
|
||||
|
||||
db.execute("",
|
||||
params![]
|
||||
);
|
||||
|
||||
match db
|
||||
.query(
|
||||
"INSERT INTO website $array
|
||||
@ -89,32 +90,10 @@ pub struct Record {
|
||||
pub id: Thing,
|
||||
}
|
||||
|
||||
#[instrument(skip_all, name = "SurrealDB")]
|
||||
pub async fn connect(config: &Config) -> surrealdb::Result<Surreal<Client>> {
|
||||
trace!("Establishing connection to surreal...");
|
||||
#[instrument(skip_all, name = "sqlite_connect")]
|
||||
pub async fn connect(config: &Config) -> Result<Connection, rusqlite::Error> {
|
||||
trace!("Establishing connection to sqlite...");
|
||||
// Connect to the server
|
||||
let db = Surreal::new::<Ws>(&config.surreal_url).await?;
|
||||
|
||||
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)
|
||||
Connection::open("./squeelite.db")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user