97e24d0d41
* Add record migration * Add database functions for inserting history No real tests yet :( I would like to avoid running postgres lol * Add index handler, use UUIDs not strings * Fix a bunch of tests, remove Option<Uuid> * Add tests, all passing * Working upload sync * Record downloading works * Sync download works * Don't waste requests * Use a page size for uploads, make it variable later * Aaaaaand they're encrypted now too * Add cek * Allow reading tail across hosts * Revert "Allow reading tail across hosts" Not like that This reverts commit 7b0c72e7e050c358172f9b53cbd21b9e44cf4931. * Handle multiple shards properly * format * Format and make clippy happy * use some fancy types (#1098) * use some fancy types * fmt * Goodbye horrible tuple * Update atuin-server-postgres/migrations/20230623070418_records.sql Co-authored-by: Conrad Ludgate <conradludgate@gmail.com> * fmt * Sort tests too because time sucks * fix features --------- Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
71 lines
2.1 KiB
Rust
71 lines
2.1 KiB
Rust
use ::sqlx::{FromRow, Result};
|
|
use atuin_common::record::{EncryptedData, Record};
|
|
use atuin_server_database::models::{History, Session, User};
|
|
use sqlx::{postgres::PgRow, Row};
|
|
|
|
pub struct DbUser(pub User);
|
|
pub struct DbSession(pub Session);
|
|
pub struct DbHistory(pub History);
|
|
pub struct DbRecord(pub Record<EncryptedData>);
|
|
|
|
impl<'a> FromRow<'a, PgRow> for DbUser {
|
|
fn from_row(row: &'a PgRow) -> Result<Self> {
|
|
Ok(Self(User {
|
|
id: row.try_get("id")?,
|
|
username: row.try_get("username")?,
|
|
email: row.try_get("email")?,
|
|
password: row.try_get("password")?,
|
|
}))
|
|
}
|
|
}
|
|
|
|
impl<'a> ::sqlx::FromRow<'a, PgRow> for DbSession {
|
|
fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> {
|
|
Ok(Self(Session {
|
|
id: row.try_get("id")?,
|
|
user_id: row.try_get("user_id")?,
|
|
token: row.try_get("token")?,
|
|
}))
|
|
}
|
|
}
|
|
|
|
impl<'a> ::sqlx::FromRow<'a, PgRow> for DbHistory {
|
|
fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> {
|
|
Ok(Self(History {
|
|
id: row.try_get("id")?,
|
|
client_id: row.try_get("client_id")?,
|
|
user_id: row.try_get("user_id")?,
|
|
hostname: row.try_get("hostname")?,
|
|
timestamp: row.try_get("timestamp")?,
|
|
data: row.try_get("data")?,
|
|
created_at: row.try_get("created_at")?,
|
|
}))
|
|
}
|
|
}
|
|
|
|
impl<'a> ::sqlx::FromRow<'a, PgRow> for DbRecord {
|
|
fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> {
|
|
let timestamp: i64 = row.try_get("timestamp")?;
|
|
|
|
let data = EncryptedData {
|
|
data: row.try_get("data")?,
|
|
content_encryption_key: row.try_get("cek")?,
|
|
};
|
|
|
|
Ok(Self(Record {
|
|
id: row.try_get("client_id")?,
|
|
host: row.try_get("host")?,
|
|
parent: row.try_get("parent")?,
|
|
timestamp: timestamp as u64,
|
|
version: row.try_get("version")?,
|
|
tag: row.try_get("tag")?,
|
|
data,
|
|
}))
|
|
}
|
|
}
|
|
|
|
impl From<DbRecord> for Record<EncryptedData> {
|
|
fn from(other: DbRecord) -> Record<EncryptedData> {
|
|
Record { ..other.0 }
|
|
}
|
|
}
|