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

Import syntax #29

Open
orangemug opened this issue Jul 11, 2016 · 0 comments
Open

Import syntax #29

orangemug opened this issue Jul 11, 2016 · 0 comments

Comments

@orangemug
Copy link
Owner

I want to be able to require a file once. The aim is to be able to require a dependency, only the first call to require a file will actually insert the file in the SQL the rest will be a null operation.

The suggested syntax is {#./file/path.sql} where the conditions are

  • Must be at the top of a file before any SQL (defined as non-whitespace)
  • Must not be required by any other file

The use case is for easily building schemas (especially for tests)

For example given

/* filepath: ./users.sql */
CREATE TABLE users (
  id          INTEGER,
  username    varchar(30),        
  role        varchar(30),
  status      varchar(30)
);

You could add ./users.sql as a dependency of ./friends.sql

/* filepath: ./friends.sql */
{#./users.sql}

CREATE TABLE friends (
  id     INTEGER,
  fromId INTEGER,
  toId   INTEGER
);

However you could also include it in another schema

/* filepath: posts.sql */
{#./users.sql}

CREATE TABLE posts (
  id     INTEGER,
  owner  INTEGER,
  title  varchar(30),
  body   varchar(1000)
);

The advantage in this approach is

  • Able to see your table dependencies
  • Loading a partial schema for testing queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant