-- This works as the default sql handler for .sql files
-- Inherit your preferred module.

-- lx format
local format = require("core.format")

format.register({
	name = "Structured Query Language",
	shortname = "SQL",
	extensions = {
		"sql",
		"ddl",	-- SQL schema definition script
		"ddm",	-- SQL data manipulation script
	},
	inherit = {
		syntax = "module:sql_mysql",
		keys = { "comment", "patterns", "symbols" },
	},
	outline_patterns = {
		{ pattern = "%s*SELECT%s+",    line_start = true, caseless = true }, -- Query statement
		{ pattern = "%s*WITH%s+",      line_start = true, caseless = true }, -- Common table expression

		{ pattern = "%s*INSERT%s+",    line_start = true, caseless = true }, -- Insert statement
		{ pattern = "%s*UPDATE%s+",    line_start = true, caseless = true }, -- Update statement
		{ pattern = "%s*DELETE%s+",    line_start = true, caseless = true }, -- Delete statement
		{ pattern = "%s*MERGE%s+",     line_start = true, caseless = true }, -- Merge statement

		{ pattern = "%s*CREATE%s+",    line_start = true, caseless = true }, -- Create statement
		{ pattern = "%s*LOCK%s+",      line_start = true, caseless = true }, -- Lock statement
		{ pattern = "%s*ALTER%s+",     line_start = true, caseless = true }, -- Alter statement
		{ pattern = "%s*DROP%s+",      line_start = true, caseless = true }, -- Drop statement
		{ pattern = "%s*TRUNCATE%s+",  line_start = true, caseless = true }, -- Truncate statement

		{ pattern = "%s*EXPLAIN%s+",   line_start = true, caseless = true }, -- Explain statement
		{ pattern = "%s*DESCRIBE%s+",  line_start = true, caseless = true }, -- Describe statement
		{ pattern = "%s*DESC%s+",      line_start = true, caseless = true }, -- Short describe statement
		{ pattern = "%s*SHOW%s+",      line_start = true, caseless = true }, -- Show statement
		{ pattern = "%s*USE%s+",       line_start = true, caseless = true }, -- Use database statement
		{ pattern = "%s*SET%s+",       line_start = true, caseless = true }, -- Set statement

		{ pattern = "%s*CALL%s+",      line_start = true, caseless = true }, -- Call statement
		{ pattern = "%s*EXECUTE%s+",   line_start = true, caseless = true }, -- Execute statement
		{ pattern = "%s*EXEC%s+",      line_start = true, caseless = true }, -- Short execute statement
		{ pattern = "%s*DECLARE%s+",   line_start = true, caseless = true }, -- Declare statement

		{ pattern = "%s*BEGIN%s+",     line_start = true, caseless = true }, -- Transaction begin
		{ pattern = "%s*COMMIT%s*",    line_start = true, caseless = true }, -- Transaction commit
		{ pattern = "%s*ROLLBACK%s*",  line_start = true, caseless = true }, -- Transaction rollback
		{ pattern = "%s*SAVEPOINT%s+", line_start = true, caseless = true }, -- Savepoint statement
		{ pattern = "%s*RELEASE%s+",   line_start = true, caseless = true }, -- Release savepoint statement

		{ pattern = "%s*GRANT%s+",     line_start = true, caseless = true }, -- Grant statement
		{ pattern = "%s*REVOKE%s+",    line_start = true, caseless = true }, -- Revoke statement

		{ pattern = "%s*ANALYZE%s*",   line_start = true, caseless = true }, -- Analyze statement
		{ pattern = "%s*VACUUM%s*",    line_start = true, caseless = true }, -- Vacuum statement
		{ pattern = "%s*PRAGMA%s+",    line_start = true, caseless = true }, -- Pragma statement
	},
})
