wasm_run icon indicating copy to clipboard operation
wasm_run copied to clipboard

typesql_parser maintainer

Open moshe5745 opened this issue 1 year ago • 10 comments

Hi.

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

moshe5745 avatar Nov 14 '24 07:11 moshe5745

Hi thanks for the issue.

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

juancastillo0 avatar Nov 18 '24 18:11 juancastillo0

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?

moshe5745 avatar Nov 19 '24 16:11 moshe5745

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.

juancastillo0 avatar Nov 23 '24 16:11 juancastillo0

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

moshe5745 avatar Nov 23 '24 17:11 moshe5745

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.

juancastillo0 avatar Nov 23 '24 17:11 juancastillo0

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 :))

moshe5745 avatar Nov 23 '24 18:11 moshe5745

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.

juancastillo0 avatar Nov 24 '24 00:11 juancastillo0

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.

moshe5745 avatar Nov 24 '24 07:11 moshe5745

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 avatar Nov 24 '24 23:11 juancastillo0

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.

juancastillo0 avatar Nov 25 '24 02:11 juancastillo0