askql icon indicating copy to clipboard operation
askql copied to clipboard

Add namespacing/modules

Open pkarw opened this issue 3 years ago • 6 comments

Is your feature request related to a problem? If yes, please describe the problem.

When we'd like to implement a more broad set of the resources/integrations we'll encounter a namespacing issue, kind of modules/namespaces/groups would be a handy solution to it.

For example when we'd like to develop the resources for accessing MySQL and MongoDB both ORM modules could potentially have a method like mysql:findOne({}) / mongodb:findOne({}). There's actually no way for avoid resource overlapping other than naming convention (egmysql_findOne() - which actually is not an elegant solution)

pkarw avatar Apr 23 '21 08:04 pkarw

... the simplest possible solution could be to extend the run() method on vm to let the officially registered resources return methods or return sub-resources (chaining) etc. we're not talking about the OOP methods - however this could potentially be a great solution too

pkarw avatar Apr 23 '21 08:04 pkarw

@pkarw , the issue I see here is that currently code like mysql:findOne() is just a syntactic sugar over findOne(mysql), which means that regardless what kind of variable mysql is, the very same findOne() function will be called. The translation is not done in run() in vm, which is called when executing the parsed program, but much earlier - when parsing the AskScript source code into AST.

czerwinskilukasz1 avatar May 02 '21 10:05 czerwinskilukasz1

On the other hand, what I think we could do is to have a way to return a MySQL object which has a number of fields, each of them being a function (e.g. field findOne being a function for finding a single row in a table etc.) and then run mysql.findOne(). Please note that here we use dot instead of the colon. In AskScript we used colon for the "method" syntax sugar and method chaining, but dot for accessing properties (see e.g. this sample .ask file: https://github.com/CatchTheTornado/askql/blob/master/src/askscript/tests/08-objects-records/objects-14-key_access.ask )

czerwinskilukasz1 avatar May 02 '21 11:05 czerwinskilukasz1

This way we could have:

// mysql - a resource that has several fields with functions, e.g. connect 
conn = mysql.connect('host', 'user', 'pass')
conn.useDb('dbname')
row = conn.findOne('text to search for')

czerwinskilukasz1 avatar May 02 '21 11:05 czerwinskilukasz1

@czerwinskilukasz1 good point. I think it's a great way to go for this FR; it's somewhat clarifying the #580 as well (I mean the "dot" notation could be used to have both #579 and #580 up)

pkarw avatar May 03 '21 12:05 pkarw

Blocked by https://github.com/CatchTheTornado/askql/issues/589

mhagmajer avatar May 18 '21 15:05 mhagmajer