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

typesql_parser maintainer #63

Open
moshe5745 opened this issue Nov 14, 2024 · 10 comments
Open

typesql_parser maintainer #63

moshe5745 opened this issue Nov 14, 2024 · 10 comments

Comments

@moshe5745
Copy link

Hi.

wanted to ask some question about this package from pub.dev: https://pub.dev/packages/typesql_parser

@juancastillo0
Copy link
Owner

Hi thanks for the issue.

Yes, you can send the question through this repo. I may be able to help you.

@moshe5745
Copy link
Author

First thing first - Where is the repo for this package? I cant find it.
The second question is that I understand this is a wrapper on other rust package.
So I wanted to understand how it works. I wanted to see the src code(in github) - so this is connected to the first question.
Anyway I checked my local files of the package and saw that you using wasm module(super cool).
So the third question is that the reason(using wasm module) that the createTypesqlParser is async?

@juancastillo0
Copy link
Owner

All the directories for each package in the repo are presented in the readme. The typesql_parser source code can be found in the /packages/wasm_packages/typesql_parser directory and the Rust implementation is within the typesql_parser_wasm directory.

That's right, since the compilation of the wasm module may take some time it's better to make it async.

@moshe5745
Copy link
Author

I dont see the visitor functionality that present in rust lib.
Do you have plans to implement it?

@juancastillo0
Copy link
Owner

Thanks for your great questions, and sorry there aren't many docs about the package.

The visitor implementation is exposed within the /lib/visitor.dart file and an usage example is the DependenciesVisitor class in the typesql package.

@moshe5745
Copy link
Author

I see you started to implement typesql_generator
I see its not finished. Am I right?

I am trying to build a generator too. Like sqlc package in golang(But maybe better :))

@juancastillo0
Copy link
Owner

You can try it out and let me know what you think, it's on pub.dev. I believe it supports most primitives and even JSON. If there is something missing you may create an issue or open a PR.

@moshe5745
Copy link
Author

Hmm...

Right now its generating me code with errors. For example:

-- name: complexQuery :many
select employee_id, name, department_id, salary
from employees
where
    (department_id = ? or ? is null)
    and (salary >= ? or ? is null)
    and (hire_date between ? and ? or (? is null and ? is null))
    and (skills->>? = ? OR ? IS NULL)
ORDER BY
    CASE WHEN ? = 'salary' THEN salary END DESC,
    CASE WHEN ? = 'hire_date' THEN hire_date END DESC
LIMIT ? OFFSET ?;

-- name: getUsersByStatus :many
select * from users
where status = ?;

-- name: insertNewUser :exec
insert into users (name, email, status)
values (?, ?, ?);

-- name: getUsersByIds :many
select * from users
where id in (?, ?, ?);

-- name: getUsersByAgeRange :many
select * from users
where age between ? and ?;

-- name: getLimitedUsers :many
select * from users
LIMIT ? offset ?;

-- name: getGroupsByCount :many
select status, count(*)
from users
group by status
having count(*) > ?;

-- name: orderUsersByColumn :many
select * from users
order by ? asc;

Maybe I am using it the wrong way? Tried to delete the comments in this file too with same result.

@juancastillo0
Copy link
Owner

I believe the error could be due to the name property. You have to configure it as a JSON like the example.

Is there an error? Or perhaps you could provide the generated dart code?

@juancastillo0
Copy link
Owner

You will also need to provide the CREATE TABLE SQL statements within the .sql file, otherwise the generator will not know which tables and views are available, and their types.

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

2 participants