1use sqlx::database::HasArguments;
2use sqlx::query::QueryAs;
3use sqlx::{Database, Encode, Executor, FromRow, IntoArguments, Type};
4
5pub trait Schema {
6 type Id: Send;
7
8 fn table_name() -> &'static str;
9
10 fn id(&self) -> Self::Id;
12
13 fn id_column() -> &'static str;
15
16 fn columns() -> &'static [&'static str];
18}
19
20pub trait Binds<'e, E>
21where
22 Self: 'e + Sized + Send + Unpin + for<'r> FromRow<'r, <E::Database as Database>::Row> + Schema,
23 <Self as Schema>::Id:
24 Encode<'e, <E as Executor<'e>>::Database> + Type<<E as Executor<'e>>::Database>,
25 E: Executor<'e> + 'e,
26 <E::Database as HasArguments<'e>>::Arguments: IntoArguments<'e, <E as Executor<'e>>::Database>,
27{
28 fn insert_binds(
29 &'e self,
30 query: QueryAs<'e, E::Database, Self, <E::Database as HasArguments<'e>>::Arguments>,
31 ) -> QueryAs<'e, E::Database, Self, <E::Database as HasArguments<'e>>::Arguments>;
32
33 fn update_binds(
34 &'e self,
35 query: QueryAs<'e, E::Database, Self, <E::Database as HasArguments<'e>>::Arguments>,
36 ) -> QueryAs<'e, E::Database, Self, <E::Database as HasArguments<'e>>::Arguments>;
37}