Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a different name than "id" for the primary key #148

Open
saemideluxe opened this issue May 18, 2022 · 8 comments
Open

Using a different name than "id" for the primary key #148

saemideluxe opened this issue May 18, 2022 · 8 comments

Comments

@saemideluxe
Copy link

No description provided.

@saemideluxe
Copy link
Author

Okay, so this actually going to be a real issue I would like to open, as I did not find something about it in the docs or other issues: Is it possible to read from a database whose tables do not have a column "id" as the primary key but something else? I am mainly concerned about accessing existing sqlite databases, and this might be an issue for me. (Also, as a side note: I might start to work on a transpiler which parses sqlite schemas and produces norm types as output, for the same reason)

@saemideluxe saemideluxe reopened this May 18, 2022
@saemideluxe saemideluxe changed the title Primary key Using a different name than "id" for the primary key May 18, 2022
@moigagoo
Copy link
Owner

moigagoo commented Jun 4, 2022

I've looked into this issue and found the blocker that I need to resolve in order to proceed with the actual solution.

Currently, the SQL that is generated for Postgres doesn't allow any customization in primary key name or type. It's hardcoded as colShmParts.add "BIGSERIAL PRIMARY KEY". I need to switch to the more flexible Postgres syntax for primary key declaration.

I've been really busy with other stuff lately but I'm determined to find the time to move Norm forward.

@saemideluxe
Copy link
Author

Great, thanks for the response :-)

@sgmihai
Copy link

sgmihai commented Jul 31, 2022

I was just considering using norm to clean up my code that has way too much raw SQL, but this seems like a big issue. I'd like to create sqlite tables that have a custom name for the primary key, with value that I provide, not generated automatically.

@moigagoo
Copy link
Owner

I did approach this problem but it turned out to be a lot harder than I had thought initially. It's very convenient to have "id" as a reserved special column name for query generation, so there are many places in the code where this is used.

@saemideluxe
Copy link
Author

I see. Thanks for looking at it anyway!

@gwque
Copy link

gwque commented Dec 12, 2023

I was similarly hoping there was a way to use something other than "id". We prefix all our id columns with the table name, such as "customerId" where "customer" is the name of the table. Would that be possible to handle as an enhancement?

@moigagoo
Copy link
Owner

@gwque unfortunately id is a reserved name and many places in the code depend on it.

You can have your customers and stuff along with id if that's a viable option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Candidates
Development

No branches or pull requests

4 participants