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

Please add SQL support #10

Closed
oxygen opened this issue Aug 11, 2018 · 6 comments
Closed

Please add SQL support #10

oxygen opened this issue Aug 11, 2018 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@oxygen
Copy link

oxygen commented Aug 11, 2018

You are a life saver.
Would it be difficult to add SQL support in the same way (the same SQL support VS code comes prepacked with)?

@0x00000001A
Copy link
Owner

@oxygen
I guess, it should be easy to add SQL support. Can you provide some examples, how it should looks like, please?

@0x00000001A 0x00000001A self-assigned this Aug 11, 2018
@0x00000001A 0x00000001A added the enhancement New feature or request label Aug 11, 2018
@oxygen
Copy link
Author

oxygen commented Aug 11, 2018

Some MySQL SQL with variables concatenated using ${}.
It has subqueries, comments, functions with arguments (including JSON stuff from MySQL) and ${} concats.

const strQuery = `
	-- Test comment
	-- Some other comment about.someQueue.else

	SELECT
		queue.id,
		queue.timestamp,
		queue.someInt,
		queue.column
	FROM queue

	/* Block comment */
	LEFT JOIN queue AS queue_blocked ON (
		queue_blocked.id_blocked IS NOT NULL
		AND

		/* 
			Block comment 
			Block comment 
		*/
		queue_blocked.type IN ('someQueue')

		AND
		queue_blocked.id_blocked = queue.id
		AND
		queue_blocked.status NOT IN ('success', 'failed')
	)
	WHERE
		-- Comment about noQueue
		queue_blocked.id IS NULL

		AND
		queue.type IN ('someQueue')
		AND
		queue.status NOT IN ('success', 'failed')
		AND
		(
			(
				queue.retry_count < queue.retry_max

				-- Avoid running this too often (too soon)
				AND
				UNIX_TIMESTAMP(TIMESTAMP(NOW())) - UNIX_TIMESTAMP(TIMESTAMP(REPLACE(REPLACE(queue.updated_timestamp, 'T', ' '), 'Z', ''))) >= queue.retry_min_sec
			)
			OR
			queue.call_count = 0
		)

		-- Slow subquery replaced by LEFT JOIN + WHERE filtering trick.
		/*AND
		NOT EXISTS (
			SELECT
				1 AS it_exists
			FROM queue AS queue_A
			WHERE
				-- Optimization, doesn't affect results.
				queue_A.type IN ('someQueue')

				-- Optimization, doesn't affect results.
				AND
				queue_A.status NOT IN ('success', 'failed')

				-- Optimization, doesn't affect results.
				-- This optimization made the whole query 5 (five) times faster.
				AND
				(
					queue_A.group_id = queue.group_id
					OR
					(
						queue_A.group_id IS NULL
						AND
						queue.group_id IS NULL
					)
				)

				-- The mandatory condition
				AND
				queue_A.id_blocked = queue.id
			LIMIT 1
		)*/


		AND
		(
			queue.id_blocked_by IS NULL
			OR
			NOT EXISTS(
				SELECT
					1 AS it_exists
				FROM queue AS queue_C
				WHERE
					(
						queue_C.group_id = queue.group_id
						OR
						(
							queue_C.group_id IS NULL
							AND
							queue.group_id IS NULL
						)
					)
					AND
					queue_C.id = queue.id_blocked_by
				LIMIT 1
			)
		)
		AND
		(
			queue.id NOT IN (${this.runningQueueIDs().length ? this.runningQueueIDs().join(",") : 0})
			OR
			(
				queue.mark_for_death IN ('kill' ,'stop_retrying', 'kill_and_stop_retrying')
				AND
				queue.process_info_json IS NOT NULL
				AND
				JSON_EXTRACT(queue.process_info_json, "$.property") = ${escape(arch())}
				AND
				JSON_EXTRACT(queue.process_info_json, "$.pid") = ${escape(strSomeJavaScriptStringVar)}
			)
		)
	ORDER BY
		queue.id ASC
	LIMIT ${this._objQueueConfig.max_workers - this.runningQueueIDs().length}
`;

It should be colored like how VS Code already colors inside normal .sql files.

@0x00000001A
Copy link
Owner

0x00000001A commented Aug 12, 2018

@oxygen

Added SQL support (/*sql*/ or /*inline-sql*/, same for single-line comments) in 877f19e
Extension in Marketplace is updated

Feel free to make any suggestions
Thankyou

@oxygen
Copy link
Author

oxygen commented Aug 12, 2018

Flawless.

If you have StackOverflow, drop an answer here please:

https://stackoverflow.com/questions/50408369/how-to-get-injected-sql-syntax-highlighting-in-javascript-files-in-visual-studio

And I will award you a large bounty.
I'll also donate to you later.

Thank you very much!!!

@0x00000001A
Copy link
Owner

I left SO a few years ago. So, feel free to answer your question and accept it. Sorry about that.
Happy to help you

Feel free to make any suggestions or report a bug.
Anyway, since I started to add support for other languages, this feature (SQL) is "beta". I mean, I'm not sure, if it will work correctly and I have to finish some features. But I will do it in feature releases.

Feel free to close this issue, when you will check SQL support

@oxygen oxygen closed this as completed Aug 13, 2018
@oxygen
Copy link
Author

oxygen commented Aug 14, 2018

All good.
Sent you a few beers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants