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

added server example to readme #303

Merged
merged 1 commit into from May 6, 2016
Merged

Conversation

vogievetsky
Copy link
Collaborator

Hi @sidorares,
Wanted to share what I am using mysql2 for. Also I just published a blog post about it.

Basically for a while now I have been developing Plywood which is an OLAP focused query planner. It provides a query layer to make it convenient to write interactive applications. While Plywood can and will eventually support many backends, currently it supports MySQL, Druid, and native JS.

PlyQL is a MySQL compatible(ish) language that gets translated into Plywood. Recently I integrated mysql2 into plyql, a command line tool, that effectively provides a SQL interface to Druid - Druid does not speak SQL natively.

plyql goes far to support all sorts of metadata queries that typical ODBC and JDBC drivers make, you know stuff like this, this, and this. I plan to continue developing plyql (and mysql2) to a point where most read-only operations in most MySQL clients will be supported.

@sidorares
Copy link
Owner

👍
one small nitpick - in future commits reference subsystem ( such as build/tests/protocol/server/docs ) and add some context, for example "docs: add PlyQL to a list of server users"

@sidorares sidorares merged commit 33095dd into sidorares:master May 6, 2016
@sidorares
Copy link
Owner

something I was thinking about lately and maybe you could have a good input @vogievetsky :

At the moment server api is very low level, even lower then client, you operate on packet level and not "commands". While this gives a great flexibility, for most user this is too low. Would be good to discuss some better api ( maybe as separate library, maybe even include sql parser ) Use cases this library might help to cover:

  • direct 1-1 proxy server, log some stats about commands
  • federation server ( need to decide something based on a query )
  • automatic read/write split between seperate outgoing servers ( need to detect if query is read or r/w )
  • auth gateway ( use ldap / ntlm / ssh to authenticate incoming mysql connections

@vogievetsky
Copy link
Collaborator Author

vogievetsky commented May 6, 2016

I am not sure I follow 100% regarding the you operate on packet level and not "commands" : the events emitted by the server like query and field_list correspond to commands no? I think once the other commands are added in like fashion it will be a very consistent API.

Regarding your use cases:

direct 1-1 proxy server, log some stats about commands

Isn't this is totally possible right now? This is actually how I started using/testing mysql2

federation server ( need to decide something based on a query )

This needs to be paired with an SQL parser. Is there a good generic MySQL parser in JavaScript?
I looked at https://github.com/alibaba/nquery but could not use it for PlyQL because of GPLv2 license (PlyQL uses the more permissive Apache 2.0). I decided to roll my own. I licensing would allow I think we could make a cool example for mysql2 using nquery.

automatic read/write split between seperate outgoing servers ( need to detect if query is read or r/w )

Same as above

auth gateway ( use ldap / ntlm / ssh to authenticate incoming mysql connections

Again, I think this is pretty easy to do with the current server API (maybe once the handshake is more flushed out - I want to do that btw).

I think that what needs to be done now is that the server needs to become complete: compression, proper, handshake, capability flag management, other commands that are not 'known' yet, e.t.c

Could elaborate on what the server API is missing (other than a SQL parser)?

@sidorares
Copy link
Owner

yes, all use cases I mentioned are possible to handle now (for last one AuthSwitch request would be helpful - see mysqljs/mysql#1396 ) , I'm talking about good high level api to make top 80% very easy to implement.

For example, it's relatively easy to build http proxy using built in node http module, but using https://github.com/nodejitsu/node-http-proxy most common use case ( pass request as is ) is very simple api call proxy.web(req, res);

the events emitted by the server like query and field_list correspond to commands no?

The "commands" in the client are state machines, and they change state based on the packet received: value returned from command.execute(packet) becomes next execute() function. query command, for example, is responsible for all transitions described by this diagram (well, not all, "more data" is currently not supported, but there are parts that supported and not on the diagram - multiple statements, select infile etc):

graphviz-3ab2ba81081a7f3cc556d11fd09f50341bba6f15

what I'm talking is that we currently don't have server-side version of "query command" and currently in the server handler one must implement all this logic manually

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

Successfully merging this pull request may close these issues.

None yet

2 participants