indents(sql): initial support (#4857)

* indents(sql): initial support

* indents(sql): fix queries and lua style
This commit is contained in:
Matthias Q 2023-05-25 07:53:14 +02:00 committed by GitHub
parent 9bef726044
commit dae928b3bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 86 additions and 0 deletions

27
queries/sql/indents.scm Normal file
View file

@ -0,0 +1,27 @@
[
(select)
(cte)
(column_definitions)
(case)
(subquery)
(insert)
] @indent.begin
(compound_statement
(keyword_begin)
) @indent.begin
(column_definitions ")" @indent.branch)
(subquery ")" @indent.branch)
(cte ")" @indent.branch)
[
(keyword_end)
(keyword_values)
(keyword_into)
] @indent.branch
(keyword_end) @indent.end

View file

@ -0,0 +1,8 @@
select
case
when a = 1 then '1'
when a = 2 then '2'
when a = 3 then '3'
else '0'
end as stmt1
from tab;

View file

@ -0,0 +1,3 @@
begin
create table foo (bar int);
end;

View file

@ -0,0 +1,4 @@
create table my_table (
id bigint,
date date
);

7
tests/indent/sql/cte.sql Normal file
View file

@ -0,0 +1,7 @@
with data as (
select
a,
b
from tab
)
select * from data;

View file

@ -0,0 +1,5 @@
insert into mytable
(column1, column2)
values
('john', 123),
('jane', 124);

View file

@ -0,0 +1,4 @@
select
a,
b
from tab;

View file

@ -0,0 +1,9 @@
select
id
from foo
where id < (
select
id
from bar
limit 1
);

19
tests/indent/sql_spec.lua Normal file
View file

@ -0,0 +1,19 @@
local Runner = require("tests.indent.common").Runner
--local XFAIL = require("tests.indent.common").XFAIL
local run = Runner:new(it, "tests/indent/sql", {
tabstop = 4,
shiftwidth = 4,
softtabstop = 0,
expandtab = true,
})
describe("indent SQL:", function()
describe("whole file:", function()
run:whole_file(".", {
expected_failures = {},
})
end)
describe("new line:", function() end)
end)