feat: publish n96 segments

This commit is contained in:
2024-11-15 18:26:23 +00:00
parent 9fdc1defaa
commit 0da9bd996f
26 changed files with 278 additions and 75 deletions

View File

@ -1274,6 +1274,7 @@ dependencies = [
"tokio-stream",
"tracing",
"url",
"uuid",
]
[[package]]
@ -1355,6 +1356,7 @@ dependencies = [
"stringprep",
"thiserror",
"tracing",
"uuid",
"whoami",
]
@ -1394,6 +1396,7 @@ dependencies = [
"stringprep",
"thiserror",
"tracing",
"uuid",
"whoami",
]
@ -1419,6 +1422,7 @@ dependencies = [
"sqlx-core",
"tracing",
"url",
"uuid",
]
[[package]]
@ -1644,6 +1648,15 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "uuid"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
dependencies = [
"getrandom",
]
[[package]]
name = "vcpkg"
version = "0.2.15"
@ -1934,6 +1947,7 @@ dependencies = [
"chrono",
"log",
"sqlx",
"uuid",
]
[[package]]

View File

@ -10,5 +10,6 @@ test-pattern = []
[dependencies]
anyhow = "^1.0.70"
chrono = { version = "0.4.38", features = ["serde"] }
sqlx = { version = "0.8.2", features = ["runtime-tokio", "migrate", "mysql", "chrono"] }
log = "0.4.22"
sqlx = { version = "0.8.1", features = ["runtime-tokio", "migrate", "mysql", "chrono", "uuid"] }
log = "0.4.22"
uuid = { version = "1.11.0", features = ["v4"] }

View File

@ -13,7 +13,7 @@ create table user
create unique index ix_user_pubkey on user (pubkey);
create table user_stream
(
id integer unsigned not null auto_increment primary key,
id UUID not null primary key,
user_id integer unsigned not null,
starts timestamp not null,
ends timestamp,

View File

@ -1,6 +1,5 @@
use crate::UserStream;
use anyhow::Result;
use log::info;
use sqlx::{MySqlPool, Row};
pub struct ZapStreamDb {
@ -49,17 +48,16 @@ impl ZapStreamDb {
}
}
pub async fn insert_stream(&self, user_stream: &UserStream) -> Result<u64> {
sqlx::query(
"insert into user_stream (user_id, state, starts) values (?, ?, ?) returning id",
)
.bind(&user_stream.user_id)
.bind(&user_stream.state)
.bind(&user_stream.starts)
.fetch_one(&self.db)
.await?
.try_get(0)
.map_err(anyhow::Error::new)
pub async fn insert_stream(&self, user_stream: &UserStream) -> Result<()> {
sqlx::query("insert into user_stream (id, user_id, state, starts) values (?, ?, ?, ?)")
.bind(&user_stream.id)
.bind(&user_stream.user_id)
.bind(&user_stream.state)
.bind(&user_stream.starts)
.execute(&self.db)
.await?;
Ok(())
}
pub async fn update_stream(&self, user_stream: &UserStream) -> Result<()> {

View File

@ -1,6 +1,7 @@
use chrono::{DateTime, Utc};
use sqlx::{FromRow, Type};
use std::fmt::{Display, Formatter};
use uuid::Uuid;
#[derive(Debug, Clone, FromRow)]
pub struct User {
@ -37,7 +38,7 @@ impl Display for UserStreamState {
#[derive(Debug, Clone, Default, FromRow)]
pub struct UserStream {
pub id: u64,
pub id: Uuid,
pub user_id: u64,
pub starts: DateTime<Utc>,
pub ends: Option<DateTime<Utc>>,