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

[Feature Request] Need a proc to trigger barebone SQL commands #146

Open
baalajimaestro opened this issue Apr 26, 2022 · 4 comments
Open

Comments

@baalajimaestro
Copy link

I would like to create indexes on my table, and it doesnt look like possible with norm. I just need a proc like dbConn.exec which supposedly does handle any sql query on postgres, but doesnt work on sqlite for some reason.

@moigagoo
Copy link
Owner

moigagoo commented May 5, 2022

DbConn is a type Norm borrows from ndb. It offers exec proc for both SQLite and Postgres:

What problem specifically are you experiencing?

@PhilippMDoerner
Copy link
Collaborator

I think currently the task of adding an index to a table would be done via using the sql con provided by norm.
It does pose an interesting idea though:
Should creating an index be done via raw SQL or should norm provide a way of facilitating this, e.g. by having an "index"-pragma ?

@moigagoo
Copy link
Owner

Should creating an index be done via raw SQL or should norm provide a way of facilitating this, e.g. by having an "index"-pragma ?

I think having a pragma for it would be great. The code would be very literal, which I like.

@PhilippMDoerner
Copy link
Collaborator

PhilippMDoerner commented Aug 23, 2022

I think having a pragma for it would be great. The code would be very literal, which I like.

It wouldn't even be that much more work, would it?

Like, basically that just means extended createTables.
Have an index pragma that you can associate a string with, like with tableName but now for indexName.
Iterate over all fields on a model object, check if the field has an index pragma.
If it does, get the index name and add it (associated with the column name) to a Table[string, seq[string]] that associates index-names with a seq of column names that have an index-pragma with that particular index-name.
Once one has iterated over all fields, you can iterate over the index-names in that table and generate an SQL statement for each.

If we want to make sure a column can be in multiple indices, we could even make it so that the String is a comma separated list of index-names and during processing we just split by comma, strip the ends of whitespaces and then add the individual fields to the table.

I think that might be it already.
Am I missing something?

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

3 participants