Skip to content

Add support for combined (multiple) primary keys#154

Open
EmilianoBruni wants to merge 59 commits intoknex:masterfrom
EmilianoBruni:master
Open

Add support for combined (multiple) primary keys#154
EmilianoBruni wants to merge 59 commits intoknex:masterfrom
EmilianoBruni:master

Conversation

@EmilianoBruni
Copy link

@EmilianoBruni EmilianoBruni commented Aug 21, 2025

This PR add support for combined (multiple) primary keys.

If there is only one primary key for a given table, it return as a string as in current version.
If table has a combined (multiple) primary keys, they are return as an array of string. (Version previous 3.1.0 doesn't support combined pks and in this case it returned the first pk only)

As side effect this PR fix a wrong detection of foreign keys in CockroachDB where always returned pk of first table.

I also update library to latest, fix github action and moved from npm to pnpm.

All tests for

  • CockroachDB,
  • Postgres,
  • MySQL,
  • MS SQL,
  • SQLite,
  • OracleDB

pass locally (pnpm test) and in GitHub Action

More...

This pull request introduces several improvements and changes to the project, focusing on enhanced support for composite primary keys, migration to pnpm, improved development and CI workflows, and updated documentation. The most significant update is the addition of support for tables with multiple-column (composite) primary keys across all supported dialects. The CI and development environment have also been modernized for better reliability and developer experience.

Primary key/composite key support:

  • Added support for composite (multi-column) primary keys in the primary method for all major dialects (cockroachdb.ts, mssql.ts, mysql.ts, oracledb.ts, postgres.ts). The return type is now string | string[] | null, returning an array for composite keys, a string for single keys (backward compatibility), or null if none.
  • Updated documentation in README.md to explain the new behavior of primary, including usage examples and notes on backward compatibility.
  • Added a changelog entry summarizing these and other changes.

Development and build tooling improvements:

  • Migrated the project from npm to pnpm, including updates to .prettierignore, Dockerfiles, and the development container configuration (.devcontainer.json, docker/dev/Dockerfile, docker/docker-compose.vscode.yml).
  • Improved Docker Compose setup: renamed and refactored docker-compose.yml to docker/docker-compose.yml, updated seed file paths, and upgraded CockroachDB image version.

CI/CD workflow enhancements:

  • Updated GitHub Actions workflow to use newer action versions, support Node.js 20 and 22, use pnpm for dependency management, and improve database service readiness checks. Temporarily set trigger to workflow_dispatch for testing.

Other improvements:

  • Fixed import of flatten in sqlite.ts to use the correct lodash subpath.
  • Updated project description in README.md to mention CockroachDB support.

Let me know if you have questions about any of these changes or want to discuss the new composite primary key support in detail!

@EmilianoBruni EmilianoBruni changed the title Add support for combined (composite) primary keys Add support for combined (multiple) primary keys Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant