feat: ✨ create package
This commit is contained in:
parent
0dacf1f54f
commit
5bdc82a3a0
2 changed files with 16 additions and 3 deletions
|
@ -6,6 +6,8 @@ use surrealdb::{
|
|||
};
|
||||
use tokio::time::sleep;
|
||||
|
||||
use crate::package::Package;
|
||||
|
||||
static DB: LazyLock<Surreal<Client>> = LazyLock::new(Surreal::init);
|
||||
|
||||
pub async fn establish_connection() -> Result<(), surrealdb::Error> {
|
||||
|
@ -21,3 +23,10 @@ pub async fn is_alive() -> bool {
|
|||
_ = sleep(Duration::from_secs(1)) => false
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_package(package: Package) -> Option<Package> {
|
||||
DB.create::<Option<Package>>(package.get_name())
|
||||
.content(package)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use surrealdb::Datetime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::sql::Datetime;
|
||||
|
||||
pub(crate) struct Package {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Package {
|
||||
name: String,
|
||||
publisher: Publisher,
|
||||
version: Version,
|
||||
|
@ -14,7 +16,7 @@ pub(crate) struct Package {
|
|||
}
|
||||
|
||||
impl Package {
|
||||
fn get_name(&self) -> String {
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.to_string()
|
||||
}
|
||||
|
||||
|
@ -47,6 +49,7 @@ impl Package {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct Version {
|
||||
first: u8,
|
||||
second: u8,
|
||||
|
@ -76,6 +79,7 @@ impl Display for Version {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct Publisher {
|
||||
name: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue