Nano-SQL icon indicating copy to clipboard operation
Nano-SQL copied to clipboard

Why can column names not begin with an underscore?

Open EternityForest opened this issue 3 years ago • 1 comments

Many non-SQL databases use column names with underscores at the begining(PouchDB's _id field, etc). Is there a specific reason the schemas don't support this, or any flag to enable it?

EternityForest avatar Nov 09 '20 02:11 EternityForest

I would also like to know. Does not look like there is an option t set it as the code has checks like this:

if (!table._internal && (l.indexOf("_") === 0 || l.match(/\s/g) !== null || l.match(/[\(\)\]\[\.]/g) !== null)) {
                rej({ error: "Invalid Table Name " + table.name + "! https://docs.nanosql.io/setup/data-models", query: _this.query });
                return;
            }
if (!modelData[0] || modelData[0].match(/[\(\)\]\[\.]/g) !== null || modelData[0].indexOf("_") === 0) {
                    hasError = true;
                    rej({ error: "Invalid Data Model at " + (table.name + "." + col) + "! https://docs.nanosql.io/setup/data-models", query: _this.query });
                }

If I alter the code to exclude the check for the undescore prefix then it works perfectly fine. Maybe one of the adapters does not like it, in which case it would be possible to then add a config for it to allow it.

UPDATE: So after further investigation it seems that nano-sql uses underscores internally for table creation (I observed with SQLite) and it disallows using underscores for table and db names so as to avoid collisions most probably..

juanreynolds avatar Oct 24 '21 21:10 juanreynolds