A tool for concatenating files in topological order
Project description
topcat
topological concatenation of files
Description
topcat
is a simple tool to concatenate files in a topological order. It is useful when you have a set of files that
depend on each other and you want to concatenate them in the right order.
For my usecase this is SQL files.
I like to treat my SQL files as a set of functions and views that depend on each other. I like to keep them in separate files and concatenate them in the right order to create a single file that I can run in my database.
Usage
Lets say you have a directory with the following files:
sql
├── my_other_schema
│ ├── functions
│ │ ├── a.sql
│ │ ├── b.sql
│ │ └── c.sql
│ └── schema.sql
└── my_schema
├── functions
│ └── a.sql
└── schema.sql
And the content of the files is:
sql/my_schema/schema.sql
:
-- name: my_schema
DROP SCHEMA IF EXISTS my_schema CASCADE;
CREATE SCHEMA IF NOT EXISTS my_schema;
sql/my_schema/functions/a.sql
:
-- name: my_schema.a
-- dropped_by: my_schema
CREATE FUNCTION my_schema.a() RETURNS INT AS
$$
SELECT 1;
$$ LANGUAGE SQL IMMUTABLE
PARALLEL SAFE;
sql/my_schema/functions/b.sql
:
-- name: my_schema.b
-- dropped_by: my_schema
-- requires: my_schema.a
CREATE FUNCTION my_schema.b() RETURNS INT AS
$$
SELECT my_schema.a() + 1
$$ LANGUAGE SQL;
sql/my_schema/functions/c.sql
:
-- name: my_schema.c
-- dropped_by: my_schema
-- requires: my_schema.b
CREATE FUNCTION my_schema.c() RETURNS INT AS
$$
SELECT my_schema.b() + 1
$$ LANGUAGE SQL IMMUTABLE
PARALLEL SAFE;
sql/my_other_schema/schema.sql
:
-- name: my_other_schema
DROP SCHEMA IF EXISTS my_schema CASCADE;
CREATE SCHEMA IF NOT EXISTS my_schema;
sql/my_other_schema/functions/a.sql
:
-- name: my_other_schema.a
-- dropped_by: my_other_schema
-- requires: my_schema.b
CREATE FUNCTION my_other_schema.a() RETURNS INT AS
$$
SELECT my_schema.b() + 1
$$ LANGUAGE SQL IMMUTABLE
PARALLEL SAFE;
So the dependency graph is:
Now you can run topcat
to concatenate the files in the right order:
topcat -i tests/input/sql -o tests/output/sql/output.sql
The content of output.sql
will be:
-- This file was generated by topcat. To regenerate run:
--
-- topcat -i tests/input/sql -o tests/output/sql/output.sql -v
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_other_schema/schema.sql
-- name: my_schema
DROP SCHEMA IF EXISTS my_schema CASCADE;
CREATE SCHEMA IF NOT EXISTS my_schema;
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_other_schema/functions/a.sql
-- name: my_schema.a
-- dropped_by: my_schema
CREATE FUNCTION my_schema.a() RETURNS INT AS
$$
SELECT 1;
$$ LANGUAGE SQL;
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_other_schema/functions/b.sql
-- name: my_schema.b
-- dropped_by: my_schema
-- requires: my_schema.a
CREATE FUNCTION my_schema.b() RETURNS INT AS
$$
SELECT my_schema.a() + 1
$$ LANGUAGE SQL;
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_schema/schema.sql
-- name: my_other_schema
DROP SCHEMA IF EXISTS my_other_schema CASCADE;
CREATE SCHEMA IF NOT EXISTS my_other_schema;
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_schema/functions/a.sql
-- name: my_other_schema.a
-- dropped_by: my_other_schema
-- requires: my_schema.b
CREATE FUNCTION my_other_schema.a() RETURNS INT AS
$$
SELECT my_schema.b() + 1
$$ LANGUAGE SQL IMMUTABLE
PARALLEL SAFE;
------------------------------------------------------------------------------------------------------------------------
-- tests/input/sql/my_other_schema/functions/c.sql
-- name: my_schema.c
-- dropped_by: my_schema
-- requires: my_schema.b
-- requires: my_other_schema.a
CREATE FUNCTION my_schema.c() RETURNS INT AS
$$
SELECT my_schema.b() + my_other_schema.a() + 1
$$ LANGUAGE SQL;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for topcat-0.1.0-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308e782b4e80160143362ee42ac72087120778a5c0abeb9731eb15f1d24f0e6a |
|
MD5 | 62fb5708b3ced3dd5b4951202f094688 |
|
BLAKE2b-256 | a8e2a6c78e2cd7613b2b42b1a34455c98a8afd69c44e1db25349c6edc5f129a4 |
Hashes for topcat-0.1.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e35e1d1eddda803372a3762d8bf7b08a3d8177a192788dc52d44f59c44dc77 |
|
MD5 | 58ca4fcedd6cdf606f506abb83976d1c |
|
BLAKE2b-256 | 0e69fff52ef71039394d01678f2f6564eff5e48bfbd2b8b6b056a79b2724f6f7 |
Hashes for topcat-0.1.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9162faeca965db348bafb01a813b82143d0a1b31bb744224aa5e6404b0a2bf48 |
|
MD5 | 8761c672a885b3d276c4098ea98dcb1a |
|
BLAKE2b-256 | a608f454203ee97e8263679c636f6b6fd5646c80b87d784dfd08b13fd3b28bba |
Hashes for topcat-0.1.0-py3-none-musllinux_1_2_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 559511928cc78c10519d457daf10100a2ff3fd37cbff0e1887e115a207df78ce |
|
MD5 | 383a81eb6e4cafd74209dd12ac971913 |
|
BLAKE2b-256 | 67a2442cf44aaa965cbdbb36f5db14913fc1cbfd5b56d96d032ef3ddc6dba0ee |
Hashes for topcat-0.1.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7779a16f73270beb6a7e69b085bf63ca199fdda89288262823459fbbc06f9681 |
|
MD5 | 629207d7f4b2e3856b86d72895b9b857 |
|
BLAKE2b-256 | 1b6a943f1174eb5dd9c66485dbc32afa459e53ca2ebb1410908bcec9816db8ce |
Hashes for topcat-0.1.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82a69996b873ea7e9cb02c9f3fd38d5d825974d6e21d9cf49ab8b3c07d5d80b |
|
MD5 | a0acacad136841771b54acb300918240 |
|
BLAKE2b-256 | 4856bf1ef1f4d2717225c12067a617fb3e4699fa0aaf4552cbb2ae9a9694fb5a |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddb768fbb5397c3f348b0435ede16ac2f4e8bb05083f79836eaf6714e1871de3 |
|
MD5 | b8597f9d41664815eaba03d7797319da |
|
BLAKE2b-256 | d5ff66157961d3f8927f0012a4baf5fb6353795109085a088a0710cbe83b27f6 |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8468714075cd453c7638ea83698f27725b1f7d0c3fa9c41018139c0a49517933 |
|
MD5 | 58d6cbb280e28aba471127966f9be8a6 |
|
BLAKE2b-256 | fe7ebe2920a23a532d3c62f8a40a8e0afc577f0d7c7d016d7b11dd256f7c7d0b |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5523556ffbc7fda7368c61cf0d011df495a39fb2060efc2e34b4af0cea034e4d |
|
MD5 | fbb9937a56cef4b2f04622300bc7ba12 |
|
BLAKE2b-256 | 422de1368133e18fc2c004fece63e64f18655eb2dc8ca26a13a0b8eb68b1f97c |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a77d7534b42dc1adde5c70635603739154edfa438106b7b780489ba628a18094 |
|
MD5 | d6c939b428e92a93fae1613c6326bca4 |
|
BLAKE2b-256 | 2c649fa5e51e0c43d6e8513263c5d0f0c94629937ce1d4c021a2e4cdbb0f5aa1 |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83e1fc0008085f4f3c0b86940135f6f1d571cb8148a04fab2feac41238218775 |
|
MD5 | c2891acb967a000e3c53bd7589fcd574 |
|
BLAKE2b-256 | cbbcb6c231a964ee3fee4f43f63ae5a761a43d2ddcff175102a054f0496a5a57 |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37b674c3105fbfc7c6c6b334e99f43873fdebc40b8d2e446bb0f4b4f970ea2fa |
|
MD5 | 37071ec124da28ee6343479f46d90ebc |
|
BLAKE2b-256 | d871fa0422428de4ed36cfa5916c5372798adc5dcf470c27e3827b3a81a0a2e6 |
Hashes for topcat-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af219e7f5a7ea762aa7095aa8d0a94cd05d78d7888422ac3e06a7ca06c5d2f44 |
|
MD5 | 5d63d031cfa76430d8a6febc7706d62b |
|
BLAKE2b-256 | 92b933173d5e09f172e9d8adc3d57496e70d49615b493f8b47dae6bf13c4494d |
Hashes for topcat-0.1.0-py3-none-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecba2044419133c72edf8c3552be4100fd3db0b26df234bd5af0d89111f9630f |
|
MD5 | 6894ee47d5d8b7f5d903594264342a0d |
|
BLAKE2b-256 | 5a6cbef98a66207ea84b5e0d258c0eb159652db27e01ca66790d306db6782ad2 |
Hashes for topcat-0.1.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 429df7bed4ff2ea3b20cba9c39b01ce6a915ac26251619fc24947d0b17e810d2 |
|
MD5 | 3b8d740c59c8ff548444c86be24b7139 |
|
BLAKE2b-256 | 70503863954001d6f84a800ffedc974fbcfcc30048d2627f350e5d6356c82a13 |