Skip to content

Import syntax #29

@orangemug

Description

@orangemug

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions