Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions crates/codegen/src/rust.rs
Comment thread
onx2 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ pub struct {insert_callback_id}(__sdk::CallbackId);
write!(
out,
"
impl<'ctx> __sdk::TableLike for {table_handle}<'ctx> {{
type Row = {row_type};
type EventContext = super::EventContext;

fn count(&self) -> u64 {{ self.imp.count() }}
fn iter(&self) -> impl Iterator<Item = {row_type}> + '_ {{ self.imp.iter() }}
}}

impl<'ctx> __sdk::EventTable for {table_handle}<'ctx> {{
type Row = {row_type};
type EventContext = super::EventContext;
Expand All @@ -203,6 +211,21 @@ impl<'ctx> __sdk::EventTable for {table_handle}<'ctx> {{
self.imp.remove_on_insert(callback.0)
}}
}}

impl<'ctx> __sdk::WithInsert for {table_handle}<'ctx> {{
type InsertCallbackId = {insert_callback_id};

fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> {insert_callback_id} {{
{insert_callback_id}(self.imp.on_insert(Box::new(callback)))
}}

fn remove_on_insert(&self, callback: {insert_callback_id}) {{
self.imp.remove_on_insert(callback.0)
}}
}}
"
);
} else {
Expand All @@ -213,6 +236,14 @@ impl<'ctx> __sdk::EventTable for {table_handle}<'ctx> {{
out,
"pub struct {delete_callback_id}(__sdk::CallbackId);

impl<'ctx> __sdk::TableLike for {table_handle}<'ctx> {{
type Row = {row_type};
type EventContext = super::EventContext;

fn count(&self) -> u64 {{ self.imp.count() }}
fn iter(&self) -> impl Iterator<Item = {row_type}> + '_ {{ self.imp.iter() }}
}}

impl<'ctx> __sdk::Table for {table_handle}<'ctx> {{
type Row = {row_type};
type EventContext = super::EventContext;
Expand Down Expand Up @@ -246,6 +277,36 @@ impl<'ctx> __sdk::Table for {table_handle}<'ctx> {{
self.imp.remove_on_delete(callback.0)
}}
}}

impl<'ctx> __sdk::WithInsert for {table_handle}<'ctx> {{
type InsertCallbackId = {insert_callback_id};

fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> {insert_callback_id} {{
{insert_callback_id}(self.imp.on_insert(Box::new(callback)))
}}

fn remove_on_insert(&self, callback: {insert_callback_id}) {{
self.imp.remove_on_insert(callback.0)
}}
}}

impl<'ctx> __sdk::WithDelete for {table_handle}<'ctx> {{
type DeleteCallbackId = {delete_callback_id};

fn on_delete(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> {delete_callback_id} {{
{delete_callback_id}(self.imp.on_delete(Box::new(callback)))
}}

fn remove_on_delete(&self, callback: {delete_callback_id}) {{
self.imp.remove_on_delete(callback.0)
}}
}}
"
);

Expand All @@ -272,6 +333,21 @@ impl<'ctx> __sdk::TableWithPrimaryKey for {table_handle}<'ctx> {{
self.imp.remove_on_update(callback.0)
}}
}}

impl<'ctx> __sdk::WithUpdate for {table_handle}<'ctx> {{
type UpdateCallbackId = {update_callback_id};

fn on_update(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
) -> {update_callback_id} {{
{update_callback_id}(self.imp.on_update(Box::new(callback)))
}}

fn remove_on_update(&self, callback: {update_callback_id}) {{
self.imp.remove_on_update(callback.0)
}}
}}
"
);
}
Expand Down
Loading
Loading