selda icon indicating copy to clipboard operation
selda copied to clipboard

Table name / column attributes coupling

Open waiting-for-dev opened this issue 7 years ago • 3 comments

I'm writing an app which uses selda, but I'm managing the actual Sql schema with sqitch. For this reason, I'm not using some selda functions like createTable or dropTable. I just use selda to do CRUD operations on the data.

In order to query or change data in a table, I need to identify it, for example, with table method. This method has as second parameter the list of column attributes, like the primary index or whatever.

If I'm not wrong, column attributes are just used in order to create the schema, but, as long as selda is involved, they are useless for data read/write operations. For this reason, I think we are coupling here two different pieces of information: table name and columns information.

Do you think it would be a good idea to add a function which just identifies a table by its name, without any column attributes information?

waiting-for-dev avatar Oct 23 '18 14:10 waiting-for-dev

Now I see that the column attributes are also used in data operations. For example, in order for insertWithPk to return the last id inserted, autoPrimary attribute must be used.

waiting-for-dev avatar Oct 28 '18 06:10 waiting-for-dev

I think this would be both worthwhile and relatively easy to implement anyway.

While it's true that inserts need autoPrimary, we could easily ask the database about that (and any other attributes; backends already have to support this functionality for table validation and migrations) on the first insert and then cache it for later use, kind of like how prepared statements work at the moment.

valderman avatar Oct 28 '18 21:10 valderman

Cool. Quite a haskell beginner here, but let me know if I can help with anything.

waiting-for-dev avatar Oct 29 '18 06:10 waiting-for-dev