-
Notifications
You must be signed in to change notification settings - Fork 1
add sync API #14
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
base: master
Are you sure you want to change the base?
add sync API #14
Conversation
|
@oliverbrooks at first look there is too much duplication between the sync and async API. The only bit that actually needs to be async are the file operations. There has also been some loss of functionality for example The sync operations are tested only the end-to-end functionality, not the individual operations, which I think would have caught the error above. I think there are too many changes here and we should take a lighter step by step approach. Lets split this into a few steps
|
|
The only async parts are to do with
I've refactored the "require" operator to no longer do the async bit in the operator but as the parse function is the core of the require recursion I'm not sure how to refactor it out without a re-write of all the token parsing logic, hence the duplication. The issue in sharing code between sync and async is building the output and error stack in the context of iteration. The async flow builds an array of promises adding custom error handling where appropriate to add to the error stack. Sync on the other hand uses custom try/catch statements to build the errors. Refactor idea 1: Abstract token parsingOne way to remove the duplication might be to abstract the regex parsing and token creation so that whether async or sync a set of tokens is returned.
Refactor idea 2: Build sql then handle tokensAs the only async part is the file loading the async/sync flows could walk the SQL building a single large SQL file. It could then use common, synchronous tokenising logic. The SQL building would need to respect the param parsing effectively doing string replacements as it requires files into the master. Any thoughts on ways to do this? |
I think we almost have this here https://github.com/orangemug/sql-stamp/blob/master/lib/parser/index.js#L175-L184 I think we maybe just need to flatten our approach the real issue is with Maybe if this Became Note Then our |
Working sync API. Let me know what you think.