{"_id":"@barishnamazov/gsql","_rev":"5-c75fdbe5a6003b30f65f26f46ece88bc","name":"@barishnamazov/gsql","dist-tags":{"latest":"0.2.3"},"versions":{"0.1.0":{"name":"@barishnamazov/gsql","version":"0.1.0","keywords":["sql","schema","generics","database","postgres","compiler"],"license":"MIT","_id":"@barishnamazov/gsql@0.1.0","maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"homepage":"https://github.com/BarishNamazov/gsql-dev#readme","bugs":{"url":"https://github.com/BarishNamazov/gsql-dev/issues"},"bin":{"gsql":"dist/cli.js"},"dist":{"shasum":"b8bcddefb53641b4a8692850bc341d4d118a6c02","tarball":"https://registry.npmjs.org/@barishnamazov/gsql/-/gsql-0.1.0.tgz","fileCount":11,"integrity":"sha512-zv8b2azr2Oi/gbVbi0c2IJsx51SD9XdqaMPKCmoGVia1Mn1fxIvbFd9bKJH2CLNaqnpp+sP/ASDv8o5XDaHkqg==","signatures":[{"sig":"MEQCIFJ7DbO2oFqFUNGGiihHWkFGVhUDn4jZZbKQ5VDtwbseAiA1lk/h8YL3BFKyJUzUNw7zo1Ix9wSKZ2Fp2oZqFMIrPg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":271611},"main":"dist/index.js","type":"module","module":"src/index.ts","gitHead":"ac3235f73a59202e0ca8bf76a318fb6ad550e4c3","scripts":{"lint":"eslint .","test":"vitest run","build":"npm run build:lib && npm run build:cli && npm run make-cli-executable","format":"prettier --write --check \"src/**/*.ts\" \"test/**/*.ts\"","build:cli":"esbuild src/cli.ts --bundle --outfile=dist/cli.js --format=esm --platform=node --minify","build:lib":"esbuild src/index.ts --bundle --outdir=dist --format=esm --platform=browser --minify --external:chevrotain","typecheck":"tsc --noEmit","test:watch":"vitest","make-cli-executable":"echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js"},"_npmUser":{"name":"barishnamazov","email":"barish2003@gmail.com"},"repository":{"url":"git+https://github.com/BarishNamazov/gsql-dev.git","type":"git","directory":"packages/gsql"},"_npmVersion":"11.6.4","description":"Generic SQL - Parametric Polymorphism for SQL Schemas","directories":{},"_nodeVersion":"25.2.1","dependencies":{"chevrotain":"^11.0.3"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.8","esbuild":"^0.25.12","typescript":"^5.7.2","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gsql_0.1.0_1765745519811_0.05230820384720203","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@barishnamazov/gsql","version":"0.2.0","keywords":["sql","schema","generics","database","postgres","compiler"],"license":"MIT","_id":"@barishnamazov/gsql@0.2.0","maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"homepage":"https://github.com/BarishNamazov/gsql#readme","bugs":{"url":"https://github.com/BarishNamazov/gsql/issues"},"bin":{"gsql":"dist/cli.js"},"dist":{"shasum":"4c422c6b77b36750c8c117a9600227f49e1e64f1","tarball":"https://registry.npmjs.org/@barishnamazov/gsql/-/gsql-0.2.0.tgz","fileCount":11,"integrity":"sha512-KW3uv9YzfFm7ULw5VMEzJtwgr3+kvE8xnP/kx+WgTI25a6LRkJc6+3VO1vAoR9MnZnyDQvw9T7TcSHgal7gPTw==","signatures":[{"sig":"MEQCIHj+88/qbTLP1xGM0Q0gUWq5MdO4TpnpyuTjTVPCeryrAiBFx5HSjzogAU30Q5YwMP+beSu8PCPfyHTy4TT5N3/3Gw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":279601},"main":"dist/index.js","type":"module","module":"src/index.ts","gitHead":"331e8e8d8f3dc9d8497a124b708be91861caf1ca","scripts":{"lint":"eslint .","test":"vitest run","build":"npm run build:lib && npm run build:cli && npm run make-cli-executable","format":"prettier --write --check \"src/**/*.ts\" \"test/**/*.ts\"","build:cli":"esbuild src/cli.ts --bundle --outfile=dist/cli.js --format=esm --platform=node --minify","build:lib":"esbuild src/index.ts --bundle --outdir=dist --format=esm --platform=browser --minify --external:chevrotain","typecheck":"tsc --noEmit","test:watch":"vitest","make-cli-executable":"echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js"},"_npmUser":{"name":"barishnamazov","email":"barish2003@gmail.com"},"repository":{"url":"git+https://github.com/BarishNamazov/gsql.git","type":"git","directory":"packages/gsql"},"_npmVersion":"11.6.4","description":"Generic SQL - Parametric Polymorphism for SQL Schemas","directories":{},"_nodeVersion":"25.2.1","dependencies":{"chevrotain":"^11.0.3"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","vitest":"^2.1.8","esbuild":"^0.25.12","@types/pg":"^8.11.10","typescript":"^5.7.2","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gsql_0.2.0_1765826313024_0.5791937557551525","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@barishnamazov/gsql","version":"0.2.1","keywords":["sql","schema","generics","database","postgres","compiler"],"license":"MIT","_id":"@barishnamazov/gsql@0.2.1","maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"homepage":"https://github.com/BarishNamazov/gsql#readme","bugs":{"url":"https://github.com/BarishNamazov/gsql/issues"},"bin":{"gsql":"dist/cli.js"},"dist":{"shasum":"b78ee0244d1553bdc61b692722d7fcfaa2877dbd","tarball":"https://registry.npmjs.org/@barishnamazov/gsql/-/gsql-0.2.1.tgz","fileCount":11,"integrity":"sha512-/oUfFoBKvQ3xmlrKWOgmirwtjZ/uWk5Tk0gYkmnWKxXuXi9sfjjc90yEQXBNkurxRkT0AT18qrLl0wFzxGi4aQ==","signatures":[{"sig":"MEQCIGoZAWgbyRU9DzOZirO51b/lnFqpmdo11QNWMLvpP3KeAiAZ6hnhcl2Rg/A3iyDHURKiHepcuOR/U3zQ6Al+xNRsng==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":279651},"main":"dist/index.js","type":"module","module":"src/index.ts","gitHead":"331e8e8d8f3dc9d8497a124b708be91861caf1ca","scripts":{"lint":"eslint .","test":"vitest run","build":"npm run build:lib && npm run build:cli && npm run make-cli-executable","format":"prettier --write --check \"src/**/*.ts\" \"test/**/*.ts\"","build:cli":"esbuild src/cli.ts --bundle --outfile=dist/cli.js --format=esm --platform=node --minify","build:lib":"esbuild src/index.ts --bundle --outdir=dist --format=esm --platform=browser --minify --external:chevrotain","typecheck":"tsc --noEmit","test:watch":"vitest","postversion":"git push && git push --tags","make-cli-executable":"echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js"},"_npmUser":{"name":"barishnamazov","email":"barish2003@gmail.com"},"repository":{"url":"git+https://github.com/BarishNamazov/gsql.git","type":"git","directory":"packages/gsql"},"_npmVersion":"11.6.4","description":"Generic SQL - Parametric Polymorphism for SQL Schemas","directories":{},"_nodeVersion":"25.2.1","dependencies":{"chevrotain":"^11.0.3"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","vitest":"^2.1.8","esbuild":"^0.25.12","@types/pg":"^8.11.10","typescript":"^5.7.2","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gsql_0.2.1_1765827556902_0.3612054708335488","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"@barishnamazov/gsql","version":"0.2.2","keywords":["sql","schema","generics","database","postgres","compiler"],"license":"MIT","_id":"@barishnamazov/gsql@0.2.2","maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"homepage":"https://github.com/BarishNamazov/gsql#readme","bugs":{"url":"https://github.com/BarishNamazov/gsql/issues"},"bin":{"gsql":"dist/cli.js"},"dist":{"shasum":"6af0e3e2c456c70655d8b01a79e14f83b6f00fd2","tarball":"https://registry.npmjs.org/@barishnamazov/gsql/-/gsql-0.2.2.tgz","fileCount":11,"integrity":"sha512-CXt+mnFbvcHwtv1AZSFx/M3PpRoI25XnMmNVe7JCw58nlY8nHzJnBDFASBvDMVgqhOiDq/Fze0cbTXH2AWc1qw==","signatures":[{"sig":"MEYCIQCdaA7CVQ3QdV1XZnxuSLg/30FeAlxRKuHxPyk/zRrUNgIhAPXcyyjKBn+YSX+LyOYX2wT5rkVvOVi8aUdug1Aazggv","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":281413},"main":"dist/index.js","type":"module","module":"src/index.ts","gitHead":"ce96cc04a076cfd797ba2248006ed2a2ef6f4334","scripts":{"lint":"eslint .","test":"vitest run","build":"npm run build:lib && npm run build:cli && npm run make-cli-executable","format":"prettier --write --check \"src/**/*.ts\" \"test/**/*.ts\"","build:cli":"esbuild src/cli.ts --bundle --outfile=dist/cli.js --format=esm --platform=node --minify","build:lib":"esbuild src/index.ts --bundle --outdir=dist --format=esm --platform=browser --minify --external:chevrotain","typecheck":"tsc --noEmit","test:watch":"vitest","postversion":"git push && git push --tags","make-cli-executable":"echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js"},"_npmUser":{"name":"barishnamazov","email":"barish2003@gmail.com"},"repository":{"url":"git+https://github.com/BarishNamazov/gsql.git","type":"git","directory":"packages/gsql"},"_npmVersion":"11.6.4","description":"Generic SQL - Parametric Polymorphism for SQL Schemas","directories":{},"_nodeVersion":"25.2.1","dependencies":{"chevrotain":"^11.0.3"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","vitest":"^2.1.8","esbuild":"^0.25.12","@types/pg":"^8.11.10","typescript":"^5.7.2","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gsql_0.2.2_1765829043362_0.27583344860934544","host":"s3://npm-registry-packages-npm-production"}},"0.2.3":{"name":"@barishnamazov/gsql","version":"0.2.3","description":"Generic SQL - Parametric Polymorphism for SQL Schemas","module":"src/index.ts","type":"module","main":"dist/index.js","bin":{"gsql":"dist/cli.js"},"scripts":{"build":"npm run build:lib && npm run build:cli && npm run make-cli-executable","build:lib":"esbuild src/index.ts --bundle --outdir=dist --format=esm --platform=browser --minify --external:chevrotain","build:cli":"esbuild src/cli.ts --bundle --outfile=dist/cli.js --format=esm --platform=node --minify","make-cli-executable":"echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js","test":"vitest run","test:watch":"vitest","lint":"eslint .","format":"prettier --write --check \"src/**/*.ts\" \"test/**/*.ts\"","typecheck":"tsc --noEmit","postversion":"git push && git push --tags"},"devDependencies":{"@types/node":"^20.0.0","@types/pg":"^8.11.10","esbuild":"^0.25.12","pg":"^8.16.3","typescript":"^5.7.2","vitest":"^2.1.8"},"dependencies":{"chevrotain":"^11.0.3"},"keywords":["sql","schema","generics","database","postgres","compiler"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/BarishNamazov/gsql.git","directory":"packages/gsql"},"gitHead":"c4d88b91993ee7f972f2cd7b38a7c005c285afe1","_id":"@barishnamazov/gsql@0.2.3","bugs":{"url":"https://github.com/BarishNamazov/gsql/issues"},"homepage":"https://github.com/BarishNamazov/gsql#readme","_nodeVersion":"25.2.1","_npmVersion":"11.6.4","dist":{"integrity":"sha512-eCU0r9DW25Lj3q2BmrNiZ/FxXE92kWTvcQvFeySL5Qsr59pJkbo9pAB3Gg3uVHfGpYOb+OGR7Rbqd2ftgpkH7g==","shasum":"1701bb393bbd0bc0dbcc0e46cbdbdf4bf295f34e","tarball":"https://registry.npmjs.org/@barishnamazov/gsql/-/gsql-0.2.3.tgz","fileCount":11,"unpackedSize":283994,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDZX6bu81fN1mkhQo3ouObYrtHL33uHc0nPkdE4dM9TJAiBo24h2maw+hYLgZtmNi3GvJrdSu2SMlfOwOEQYA9LCuA=="}]},"_npmUser":{"name":"barishnamazov","email":"barish2003@gmail.com"},"directories":{},"maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gsql_0.2.3_1766421916753_0.6693177187739321"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-14T20:51:59.703Z","modified":"2025-12-22T16:45:17.109Z","0.1.0":"2025-12-14T20:51:59.963Z","0.2.0":"2025-12-15T19:18:33.186Z","0.2.1":"2025-12-15T19:39:17.056Z","0.2.2":"2025-12-15T20:04:03.509Z","0.2.3":"2025-12-22T16:45:16.924Z"},"bugs":{"url":"https://github.com/BarishNamazov/gsql/issues"},"license":"MIT","homepage":"https://github.com/BarishNamazov/gsql#readme","keywords":["sql","schema","generics","database","postgres","compiler"],"repository":{"type":"git","url":"git+https://github.com/BarishNamazov/gsql.git","directory":"packages/gsql"},"description":"Generic SQL - Parametric Polymorphism for SQL Schemas","maintainers":[{"name":"barishnamazov","email":"barish2003@gmail.com"}],"readme":"# GSQL - Generic SQL\n\n**Parametric polymorphism for SQL schemas**\n\nGSQL is a domain-specific language that brings the power of generics/templates to database schemas.\nDefine common patterns once, instantiate them freely.\n\n> Read the background story:\n> [Parametric Polymorphism for SQL](https://barish.me/blog/parametric-polymorphism-for-sql/)\n\n## The Problem\n\nWhen building relational databases, you often need to duplicate table structures with minor\nvariations. For example, in a learning management system, you might need announcements for courses,\nlessons, and exams—the same pattern repeated three times.\n\nCurrent solutions force you to choose between:\n\n- **Separate tables** - Violates DRY principles, leads to maintenance nightmares\n- **Polymorphic associations** - Sacrifices foreign key integrity and type safety\n\nGSQL solves this by letting you define reusable schema templates (concepts) that compile to\nPostgreSQL with proper foreign key constraints.\n\n## Quick Example\n\nHere is the \"LMS Dilemma\" (Courses, Lessons, Exams) solved with GSQL. We define an `Announcing`\npattern once and apply it to three different tables, generating strictly typed foreign keys for\neach.\n\n```\n// Define reusable patterns (Mixins)\nschema Timestamps {\n    created_at timestamptz nonull default(NOW());\n    updated_at timestamptz nonull default(NOW());\n}\n\n// Define a Generic Concept\n// Accepts a 'Target' type parameter to create a relationship\nconcept Announcing<Target> {\n    schema Announcements mixin Timestamps {\n        id serial pkey;\n\n        // Template variables: {Target}_id becomes course_id, lesson_id, etc.\n        {Target}_id integer nonull ref(Target.id) ondelete(cascade);\n\n        title text nonull;\n        body text nonull;\n\n        index({Target}_id);\n    }\n}\n\n// Define Concrete Schemas (in actual app these would also be concepts with generics)\nschema Courses mixin Timestamps { id serial pkey; name text; }\nschema Lessons mixin Timestamps { id serial pkey; topic text; }\nschema Exams   mixin Timestamps { id serial pkey; score int; }\n\n// Actually create tables by instantiating the Schemas/Concepts\ncourses = Courses;\nlessons = Lessons;\nexams   = Exams;\n\n// Create specific announcement tables for each entity\ncourse_announcements = Announcing<courses[course]>;\nlesson_announcements = Announcing<lessons[lesson]>;\nexam_announcements   = Announcing<exams[exam]>;\n\n// Add per-instance indexes if needed\nindex(course_announcements, created_at);\n```\n\nThis generates three announcement tables with proper foreign keys:\n\n```sql\nCREATE TABLE course_announcements (\n    id serial PRIMARY KEY,\n    course_id integer NOT NULL REFERENCES courses(id) ON DELETE CASCADE,\n    title text NOT NULL,\n    body text NOT NULL,\n    created_at timestamptz NOT NULL DEFAULT NOW(),\n    updated_at timestamptz NOT NULL DEFAULT NOW()\n);\nCREATE INDEX ON course_announcements (course_id);\n--- ...\n```\n\n## Key Features\n\n- **Schemas**: A table definition with columns, constraints, indexes, triggers\n- **Concepts**: Generic schema templates with type parameters\n- **Mixins**: Compose reusable schema fragments\n- **Template variables**: Automatic field name expansion\n- **Sibling references**: Multiple schemas within one concept can reference each other\n- **Per-instance indexes**: Add indexes after instantiation\n- **Type-safe foreign keys**: Proper FK constraints for polymorphic patterns\n- **PostgreSQL output**: Compiles to PostgreSQL, integrates with migration tools like Atlas\n\n## Try It Out\n\nTry GSQL in your browser with the [online playground](https://gsql.barish.me).\n\n## Installation\n\n```bash\nnpm install @barishnamazov/gsql\n# or\nbun install @barishnamazov/gsql\n```\n\n## Usage\n\n### Command Line\n\n```bash\n# Compile a GSQL file to SQL\ngsql compile schema.gsql -o schema.sql\n\n# Output to stdout\ngsql compile schema.gsql\n\n# Show help\ngsql --help\n```\n\n### As a Library\n\n```typescript\nimport { compile, compileToSQL } from \"@barishnamazov/gsql\";\n\n// Get detailed result\nconst result = compile(source);\nif (result.success) {\n  console.log(result.sql);\n} else {\n  console.error(result.errors);\n}\n\n// Or just get SQL (throws on error)\nconst sql = compileToSQL(source);\n```\n\n## Syntax Reference\n\n### Schemas\n\n```gsql\nschema Name mixin Mixin1, Mixin2 {\n    column_name type constraint1 constraint2;\n    index(column1, column2) unique;\n    check(expression);\n    trigger name before update on each row execute function fn();\n}\n```\n\n### Concepts\n\n```gsql\nconcept Tagging<Target> {\n    schema Tags {\n        id serial pkey;\n        name text;\n    }\n\n    schema Taggings {\n        {Target}_id integer ref(Target.id);\n        {Tags}_id integer ref(Tags.id); // sibling reference\n        index({Target}_id, {Tags}_id) unique;\n    }\n}\n\nusers = Users;\n// {Target}_id becomes user_id\n// {Tags}_id becomes user_tag_id\nuser_tags[user_tag], user_taggings = Tagging<users[user]>;\n```\n\n### Instantiation\n\n```gsql\n// Simple\ntable_name = SchemaOrConcept;\n\n// With type arguments and aliases\ntable_name = Concept<other_table[alias]>;\n\n// Multiple outputs\ntable1, table2 = ConceptWithMultipleSchemas<type_arg>;\n```\n\n**Aliases:** When instantiating a concept:\n\n- **With alias:** `exams[examHello]` → uses `examHello_id` (preserves alias as-is)\n- **Without alias:** `authors` → uses `author_id` (snake_cased from parameter name `Author`)\n\nExample:\n\n```gsql\nconcept Announcing<Target, Author> {\n    schema Announcements {\n        {Target}_id integer nonull ref(Target.id);\n        {Author}_id integer nonull ref(Author.id);\n    }\n}\n\nschema Exams { id serial pkey; }\nschema Authors { id serial pkey; }\n\nexams = Exams;\nauthors = Authors;\n\n// Creates table with exam_id and author_id columns\n// We don't need to alias authors, because the parameter name is Author\nannouncements = Announcing<exams[exam], authors>;\n```\n\n### Data Types\n\n- `serial`, `bigserial`\n- `integer`, `bigint`, `smallint`\n- `text`, `varchar(n)`, `char(n)`\n- `boolean`\n- `timestamptz`, `timestamp`, `date`, `time`\n- `jsonb`, `json`\n- `uuid`, `inet`, `citext`\n- `decimal`, `numeric`, `real`\n- `bytea`\n\n### Constraints\n\n- `pkey` - Primary key\n- `nonull` - Not null\n- `unique` - Unique constraint\n- `default(value)` - Default value\n- `ref(Table.column)` - Foreign key reference\n- `ondelete(cascade|restrict|setnull|setdefault|noaction)`\n- `check(expression)` - Check constraint\n\n## Development\n\nThis is a monorepo with multiple packages:\n\n- **`packages/gsql`** - Core library and CLI (published as `@barishnamazov/gsql`)\n- **`packages/playground`** - Browser-based playground\n\n### Building\n\n```bash\n# Build everything\nnpm run build\n\n# Build just the library\nnpm run build:gsql\n\n# Build just the playground\nnpm run build:playground\n```\n\n### Testing\n\n```bash\nnpm test\n```\n\n### Playground Development\n\n```bash\nnpm run dev:playground\n```\n\nAfter building, open `packages/playground/dist/index.html` in your browser.\n\n### Linting and Formatting\n\n```bash\nnpm run lint\nnpm run format\nnpm run typecheck:all\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}