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

Add object support to MySQL Queries #6

Open
EmreSURK opened this issue Feb 13, 2022 · 3 comments
Open

Add object support to MySQL Queries #6

EmreSURK opened this issue Feb 13, 2022 · 3 comments

Comments

@EmreSURK
Copy link

It would be better if we put object support to generate a query.

Current:

await conn.query('select name, email from users where id = ?', [userId]);
await conn.query('insert into users (name, email, age) values (?, ?, ?)', ['Bob', '[email protected]', 25]);

Target:

await conn.query('select name, email from users where ?', [ {  id : 1  } ] );
await conn.query('insert into users ? ', [ { name: 'Bob', email : '[email protected]', age: 25 } ] );

That writing provides much more flexible usage.

Please let me know what you think.

Thanks.

@insinfo
Copy link
Owner

insinfo commented Feb 18, 2022

yes it looks interesting, when I have time I will implement it, in the meantime if you want to do a PR I would appreciate it

@EmreSURK
Copy link
Author

Alright, I believe I can implement it.
I am starting it now, I will notify you in now or two weeks.

@insinfo
Copy link
Owner

insinfo commented Feb 25, 2022

@EmreSURK
I think the ideal is to implement it in a similar way to the postgres package, to maintain compatibility with previous versions
https://pub.dev/packages/postgres

List<List<dynamic>> results = await connection.query("SELECT a, b FROM table WHERE a = @aValue", substitutionValues: {
    "aValue" : 3
});

for (final row in results) {
  var a = row[0];
  var b = row[1];

} 

List<Map<String, Map<String, dynamic>>> results = await connection.mappedResultsQuery(
  "SELECT t.id, t.name, u.name FROM t LEFT OUTER JOIN u ON t.id=u.t_id");

for (final row in results) {
  var tID = row["t"]["id"];
  var tName = row["t"]["name"];
  var uName = row["u"]["name"];
}```

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