1.0.0 • Published 7 years ago

sql-include v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

sql-include

A simple pre-processor for building sql from multiple files.

To include a .sql file:

-- @include ./path/to/file.sql

To include all .sql files in a folder:

-- @include ./path/to/dir

example:

main.sql:

-- @include ./my_func.sql
select * from my_func();

my_func.sql:

create or replace function my_func() returns void as $$
declare
  -- variables go here
begin
  -- logic goes here
end;
$$ LANGUAGE plpgsql;

output.sql:

-- INCLUDE: ./my_func.sql

create or replace function my_func() returns void as $$
declare
  -- variables go here
begin
  -- logic goes here
end;

-- INCLUDE END;

select * from my_func();

file.js:

var fs = require('fs');
var sqlInclude = require('sql-include');

fs.writeFileSync('./output.sql', sqlInclude('./main.sql'));