a-hurst / klibs

A simple Python framework for writing cognitive psychology experiments
7 stars 1 forks source link

Improve Database.insert() code #30

Closed a-hurst closed 1 year ago

a-hurst commented 1 year ago

PR Description

This PR revises cleans up how values are inserted into the database. Prior to this, all values were converted into escaped strings in Python and then inserted into the database using a custom-generated INSERT query, having minor effects on float precision and generally not being the Correct Way To Do Things.

These changes make it so that database values are only coerced to their required column type before insertion and then insert them into the database directly using q-mark substitution, which is the proper way of inserting data per the sqlite3 Python docs.

This PR also adds checks to ensure that all essential database tables/columns required by the KLibs runtime are present at task launch, and adds a get_columns method to the database to provide a nice API for retrieving the names of the columns in a table (for internal use). Additionally, it deprecates the EntryTemplate class in favour of having Database.insert() as the one correct way of adding data to the database.

Merge Checklist