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

feat: sqlc.slice macro (mysql) #28

Open
zztkm opened this issue Oct 26, 2023 · 1 comment
Open

feat: sqlc.slice macro (mysql) #28

zztkm opened this issue Oct 26, 2023 · 1 comment

Comments

@zztkm
Copy link

zztkm commented Oct 26, 2023

Since I am using mysql, I would like to generate code that accepts multiple values using sqlc.slice.

Example

schema & query

create table students (
  id int not null auto_increment,
  name varchar(255) not null,
  age int not null
);

-- name: SelectStudents :many
SELECT * FROM students 
WHERE age IN (sqlc.slice("ages"));

current results:

class Querier:
    def __init__(self, conn: sqlalchemy.engine.Connection):
        self._conn = conn

    def select_students(self, *, ages: int) -> Iterator[models.Student]:
        result = self._conn.execute(sqlalchemy.text(SELECT_STUDENTS), {"p1": ages})
        for row in result:
            yield models.Student(
                id=row[0],
                name=row[1],
                age=row[2],
            )

i want:

class Querier:
    def __init__(self, conn: sqlalchemy.engine.Connection):
        self._conn = conn

    def select_students(self, *, ages: list[int]) -> Iterator[models.Student]:
         # some kind of processing
@zztkm
Copy link
Author

zztkm commented Oct 26, 2023

I have no idea how to implement it, but since Go supports it, I guess there is a way to do it.

@zztkm zztkm changed the title feat: sqlc.slice macro feat: sqlc.slice macro (mysql) Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant