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

Readme examples improvements #169

Open
Abscissa opened this issue Feb 26, 2018 · 6 comments
Open

Readme examples improvements #169

Abscissa opened this issue Feb 26, 2018 · 6 comments
Milestone

Comments

@Abscissa
Copy link

Abscissa commented Feb 26, 2018

Should split up the example in the readme into separate parts, and add new front-page examples to illustrate other key aspects of mysql-native.

@Abscissa Abscissa added this to the v2.3.0 milestone Mar 4, 2018
@EmTee70
Copy link

EmTee70 commented Mar 19, 2018

Can you please give an example of how to use asAA?
I just want to loop through a result range accessing the members by name?

Similar to:
foreach( row; result){writeln(row["col_name"])}

I found a solution hint here: https://forum.dlang.org/post/[email protected]

But some examples with loops are missing!

@Abscissa
Copy link
Author

@EmTee70
Copy link

EmTee70 commented Mar 20, 2018

That was not the point, I was wondering how I can do:
ResultRange range = conn.query("SELECT * FROM tablename");
foreach(row;range){
writeln(row[0]);
}
But with an AA.

So I ended up with:
while (!range.empty){
auto aa = range.asAA; // not intuitive for me, I thought asAA should work on the row level.
writeln(aa["col_name"]);
range.popFront;
}
I was wondering if there is a way to express this in a foreach loop?
So that foreach( aa_row; range.asAA) or foreach( row:range){ auto aa = row.asAA; }

So I want to ask you to put a foreach and/or while loop example(s) for handling the result range in your documentation, too.

@Abscissa
Copy link
Author

Ahh, I see, I misunderstood.

asAA is one of those things that predates my involvement in this lib that I haven't looked real closely into (except to be careful not to break it.)

It predates D's ranges, too, so that probably explains the weirdness of it being a method of ResultRange (and whatever the predecessor of ResultRange was called - ResultSequence, IIRC) instead of Row. Also, Row doesn't currently have access to the column names - yet. I agree this is very awkward.

I'll see what I can do about documenting this with an example.

But, FWIW, I do intend to augment Row with the ability to lookup columns by name. Aside from being a feature that's been on my personal wishlist for far too long, that should also reduce (maybe even eliminate?) the need for ResultRange.asAA. Though I might still add a Row.toAA as well, if there's still desire for it.

@EmTee70
Copy link

EmTee70 commented Mar 21, 2018

foreach(row; db.query("SELECT id, name FROM people ORDER BY name LIMIT 10"))
writeln(row[0], " ", row["name"]); // index and name supported
Do you know where this is from?
https://github.com/adamdruppe/arsd/blob/master/mysql.d

Might be useful to make it similar?

Just saw this at the bottom: Authors: Adam D. Ruppe, with contributions from Nick Sabalausky :-)

@Abscissa
Copy link
Author

Interesting. I guess he must've borrowed some stuff from either this or one of my other libs.

And yes, that's basically the syntax I had in mind for looking up a column by name. The implementation should be pretty straightforward, the hardest part is just finding the time for it and everything else :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants