Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix primary key enforcement for IndexedDB tables#2274

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge5 commits intodevelop
base:develop
Choose a base branch
Loading
fromcopilot/fix-primary-key-error

Conversation

Copy link
Contributor

CopilotAI commentedNov 30, 2025
edited
Loading

Thank you for the time you are putting into AlaSQL!

Description

Fixes#1292 - Primary keys defined in CREATE TABLE were not enforced when using IndexedDB storage, allowing duplicate values.

Root cause:IDB.createTable always created object stores with{autoIncrement: true}, ignoring user-defined primary key columns.

Changes:

  • IDB.createTable: Use IndexedDB'skeyPath option for primary key columns
    • Single-column PK:{keyPath: columnName}
    • Composite PK:{keyPath: [col1, col2, ...]}
    • No PK:{autoIncrement: true} (unchanged behavior)
  • IDB.intoTable: HandleConstraintError from IndexedDB when duplicate keys are inserted, returning consistent error message

Example:

alasql("CREATE TABLE settings (setting VARCHAR(50) PRIMARY KEY, val VARCHAR(300))");alasql("INSERT INTO settings VALUES ('domain', 'http')");alasql("INSERT INTO settings VALUES ('domain', 'https')");// Now throws: "Cannot insert record, because it already exists in primary key index"

Test: Addedtest/test1292.js covering column-level and table-level PK syntax.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • upload.wikimedia.org
    • Triggering command:/usr/local/bin/node /usr/local/bin/node node_modules/mocha/bin/mocha.js ./test --reporter dot --bail (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>primary key not working. Adds duplicate values.</issue_title>
<issue_description>I have the following code but it is not working:

alasql("create INDEXEDDB DATABASE if not exists localdb_db");alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ CREATE TABLE if not exists localdb_db.db_Settings(**setting varchar(50) Primary Key**, `value` varchar(300), storeInSession varchar(1) DEFAULT 'N')", function(res) {             console.log(res + " :indexedDB"); }); alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ INSERT INTO localdb_db.db_Settings (setting,`value` ) values(?,?)", ["domain", "http"], function(res) {             console.log(res); });         alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ INSERT INTO localkics_db.db_Settings (setting, `value` ) values(?,?)", ["domain", "https"], function(res) {             //console.log(res); }); alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ SELECT * FROM localdb_db.db_Settings", [], function(res) {             console.log(res);         });

It does not create the primary key [setting] therefore it allows me to insert duplicates. For some reason it is automatically creating its own key. I even tried by using string instead of varchar.

'#' |Key | Value
0 | 1 | {setting: “domain”, value: ”http”}
1 | 2 | {setting: “domain”, value: ”https”}

Could you please advise me what to do here?

Thank You.

</issue_description>

<agent_instructions>Please start by making a new test file named test/test1292.js and make sure we replicate the issue and the expected behavour.

Then fix the problem in the implemented code. Useyarn test to confirm.

If you need to update the grammar then please make as few changes to alasqlparser.jison as possible and runyarn jison && yarn test to confirm.

Always runyarn format before committing. </agent_instructions>

Comments on the Issue (you are@copilot in this section)


✨ Let Copilot coding agentset things up for you — coding agent works faster and does higher quality work when set up for your repo.

CopilotAIand others added2 commitsNovember 30, 2025 04:17
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix issue with primary key allowing duplicate valuesFix primary key enforcement for IndexedDB tablesNov 30, 2025
CopilotAI requested a review frommathiasrwNovember 30, 2025 04:23
Copy link
Member

@mathiasrwmathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@mathiasrwmathiasrwmathiasrw approved these changes

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

primary key not working. Adds duplicate values.

2 participants

@mathiasrw

[8]ページ先頭

©2009-2025 Movatter.jp