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

Support sqlcmd scripts #978

Open
tracker1 opened this issue Jan 21, 2020 · 2 comments
Open

Support sqlcmd scripts #978

tracker1 opened this issue Jan 21, 2020 · 2 comments

Comments

@tracker1
Copy link

tracker1 commented Jan 21, 2020

Was thinking it would be really cool to support the additional features of sqlcmd / osql in a command parameter...

sql.command(script, [commandVars])

For example:

await sql.command(script, {DatabaseName:'foo'});
  • detect in-script /\r?\n\:setvar\s+(\w+)\s+([^\r\n]+)\s*\r?\n/g;
  • remove :on error exit, always error on exit
  • splitting on /\r?\nGO;?\r?\n/g and injecting the script variables...
  • including __IsSqlCmdEnabled = True for all commands.
  • convert PRINT statements to SELECT PRINT=... - maybe use an emitter, or console.log the statements based on config?
  • running each segment as a batch, and do string replacement against Object.assign({}, detectedVars, commandVars)

I'm not entirely sure what else sqlcmd does in practice, but could be a decent idea.

@dhensby
Copy link
Collaborator

dhensby commented Jan 22, 2020

Whilst this sounds cool and nifty, I'm not sure where the need is for this and it's not something I have the time to concentrate on - I'd happily accept PRs for improvements, but this feels like a low priority for me at the moment

@tracker1
Copy link
Author

@dhensby totally understood... also, given the need to work, potentially with multiple databases and queries with GO statements, etc... not sure it's within a good scope of this project. I'm working on creating an abstraction to make it easier to find/use sqlcmd executable directly on a host, or in a locally configured docker container (assuming docker executable and container configured).

I was just reading through the generated file, and thought it might not be too much work to support such scripts. Mainly from db export/backup and from db projects in visual studio. (aside: migrating from a vs sql project to a version-script solution, so starting point is a set of these scripts).

https://github.com/tracker1/node-ms-sqlcmd

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