Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter TableRef for Any Statement Type That Implements a (New) Trait #445

Closed
nahuakang opened this issue Sep 18, 2022 · 6 comments
Closed
Assignees

Comments

@nahuakang
Copy link
Contributor

nahuakang commented Sep 18, 2022

Motivation

Issue for self-assignment and tracking :)

Following this discussion, we need to implement a trait that allows the access and modification of TableRef on all statement types that implement the said trait to continue working on sea-orm #981. The statement types that should implement this trait includes:

  • TableCreateStatement
  • TableAlterStatement
  • TableDropStatement
  • TableRenameStatement
  • TableTruncateStatement
  • IndexCreateStatement
  • IndexDropStatement
  • ForeignKeyCreateStatement
  • ForeignKeyDropStatement
  • TypeCreateStatement
  • TypeAlterStatement
  • TypeDropStatement

Proposed Solutions

The trait:

pub trait SchemaDefinitionStatement {
    fn get_table_name(&self) -> Option<&TableRef>;

    fn set_table_name(&self) -> &mut Self;

    fn prefix_table_name_with_schema<A>(&mut self, schema: A) -> &mut Self
    where
        A: IntoIden + 'static;
}

Helper on TableRef:

impl TableRef {
    pub fn schema<A>(self, schema: A) -> Self
    where
        A: IntoIden + 'static,
    {
        match self {
            ...
        }
    }
}
@nahuakang nahuakang changed the title Alter TableRef for Any Statement Type Alter TableRef for Any Statement Type That Implements a (New) Trait Sep 18, 2022
@nahuakang
Copy link
Contributor Author

@billy1624 I might try just add 1 method to SchemaDefinitionStatement since the type-related statements have TypeRef instead of TableRef and some statements have Vec<TableRef> instead of Option<TableRef>:

pub trait SchemaDefinitionStatement {
    fn prefix_table_name_with_schema<A>(&mut self, schema: A) -> &mut Self
    where
        A: IntoIden + 'static;
}

Let me know if you think it's a bad idea :)

@billy1624
Copy link
Member

@billy1624 I might try just add 1 method to SchemaDefinitionStatement since the type-related statements have TypeRef instead of TableRef and some statements have Vec<TableRef> instead of Option<TableRef>:

This make sense to me :P

But we might want to rename the trait then. Let me think...
Thoughts? @nahuakang @ikrivosheev @tyt2y3

@ikrivosheev
Copy link
Member

ikrivosheev commented Sep 30, 2022

@nahuakang maybe add associated type to trait? For work with: TypeRef, TableRef?

@nahuakang
Copy link
Contributor Author

@billy1624 also made this PR, which might resolve this issue?

@billy1624
Copy link
Member

Hey @nahuakang, you're correct! This feature is no longer needed. This is part of SeaQL/sea-orm#521 but we don't need it now as we figure out another way to achieve it.

@billy1624
Copy link
Member

I'll close this now. In case anyone interested on this. Please leave a comment and consider reopen this :)

@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants