Sublime 3 Text plugin. format inset sql, align field names and values with space.
- context-menu/format insert sql
- commands:
ctrl+shift+p
, searchformat sql
- hotkey:
ctrl+alt+l
- 格式化选择区域或全部。选择后,只格式化选择区域,反之格式化全部。
- 支持多个选区。
- 一个选区支持多个sql。
只能格式化正确的 insert sql,sql错误时会无法执行。
{Package}/InsertSqlFormatter/config.sublime-settings
中文长度,默认1.8。对齐效果比较好。应设置为常用字体的中文字宽比例。
-- origin
insert into `test`.`agent_user` ( `status`, `id`, `email`, `user_id`, `created`, `tel`, `modified`, `agent`) values ( '中文测试', '1', 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
-- formated
insert into `test`.`agent_user`
( `status` , `id`, `email` , `user_id` , `created` , `tel` , `modified` , `agent`) values
( '中文测试', '1' , 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
-- origin
insert into `test`.`agent_user` ( `status`, `id`, `email`, `user_id`, `created`, `tel`, `modified`, `agent`) values ( '中文测试', '1', 'chengxxxxxai@foxmail.com', '28950596', now(), '150xxxx1256', now(), 'WF');
-- formated
insert into `test`.`agent_user`
( `status` , `id`, `email` , `user_id` , `created`, `tel` , `modified`, `agent`) values
( '中文测试', '1' , 'chengxxxxxai@foxmail.com', '28950596', now() , '150xxxx1256', now() , 'WF');
-- origin
insert into `test`.`agent_user`
( `status`, `id`, `email`, `user_id`, `created`,
`tel`, `modified`, `agent`) values ( '中文测试',
'1', 'chengxxxxxai@foxmail.com',
'28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
-- formated
insert into `test`.`agent_user`
( `status` , `id`, `email` , `user_id` , `created` , `tel` , `modified` , `agent`) values
( '中文测试', '1' , 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
formate to single line
-- origin
insert into `test`.`agent_user` values ( '中文测试', '1', 'chengxxxxxai@foxmail.com',
'28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
-- formated
insert into `test`.`agent_user` values ( '中文测试', '1', 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
set undefined as default field name
-- origin
insert into `test`.`agent_user` ( `status`, `id`, `email`, `user_id`, `created`, `tel`, `modified`) values ( '中文测试', '1', 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF');
-- formated
insert into `test`.`agent_user`
( `status`, `id`, `email` , `user_id` , `created` , `tel` , `modified` ,undefined) values
('中文测试', '1' , 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23', 'WF' );
set null as default field value
-- origin
insert into `test`.`agent_user` ( `status`, `id`, `email`, `user_id`, `created`, `tel`, `modified`,`agent`) values ( '中文测试', '1', 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23');
-- formated
insert into `test`.`agent_user`
( `status`, `id`, `email` , `user_id` , `created` , `tel` , `modified` ,`agent`) values
('中文测试', '1' , 'chengxxxxxai@foxmail.com', '28950596', '2018-10-23', '150xxxx1256', '2018-10-23',null );