Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Select all columns #90

Closed
Sytten opened this issue Aug 5, 2021 · 8 comments
Closed

Select all columns #90

Sytten opened this issue Aug 5, 2021 · 8 comments

Comments

@Sytten
Copy link
Contributor

Sytten commented Aug 5, 2021

Hi!
I could not find an easy way to specify all columns (but not star).
Maybe Iden could implement an all() function that returns a vec?
It would look like:

Query::select().columns(MyModel::all())

Thanks!

@Progdrasil
Copy link

Progdrasil commented Aug 5, 2021

Since columns is generic on IntoIterator which all iterators implement, you could simply use the EnumIter derive from strum crate which will give you a iter() method on your enum which is the equivalent to your all

use strum::EnumIter;
use sea_query::{Iden, Query};

#[derive(Iden, EnumIter)]
enum MyModel {
    Id,
    MyColumn,
    /* etc */
}

Query::select().columns(MyModel::iter())

@Sytten
Copy link
Contributor Author

Sytten commented Aug 5, 2021

Will use it, still think it would be a good idea to have the all() since Iden can be applied to structs too.

@Progdrasil
Copy link

An Iden implementation on a struct will only give a single column reference. If you wish to associate multiple iden's to a single struct you're still going to need an enum and associate it to the struct. If you want this to all be automatically derived, you're looking for an ORM.

@Sytten
Copy link
Contributor Author

Sytten commented Aug 5, 2021

Right that make sense. I usually prefer query builders. The Iden on struct could generate Iden for all fields too or generate a DSL but I guess that would be more for an ORM.

@Progdrasil
Copy link

I think thats also in the ORM territory, since you still need to generate a list of something that implements iden. Since iden cannot give a stringified list because the query builder quotes the output of that string. You could make that it returns a list of Alias struct.

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 6, 2021

@Progdrasil thank you for helping out
@Sytten we are releasing our ORM soon (in this month), so if you are interested we'll let you know

@Sytten
Copy link
Contributor Author

Sytten commented Aug 6, 2021

@tyt2y3 I am most likely going to continue using the query builder because I have complex queries with a lot of conditionals and joins that are usually very hard to express in an ORM (thus our switch from diesel to sea-query).

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 8, 2021

Now that SeaORM is 'public', please take a look and see if it helps!
You still have full access to the SeaQuery query builder when you need it.
Please close this issue if that works for you.

@SeaQL SeaQL locked and limited conversation to collaborators Aug 13, 2021
@tyt2y3 tyt2y3 closed this as completed Aug 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants