JSON SQlite3 Create table with JSON

Viewed 3653

I'm trying to create a database table using the sqlite3 npm package. I'd like the table to have two columns, number and colour. Number should be an integer and colour should contain json data.

Is there anyway to explicitly set the data type to json in sqlite3?

Something like this below:

db.run('CREATE TABLE table1 ( number integer, colour json)');
1 Answers

While sqlite has functions for working with JSON data (Assuming the standard JSON1 extension is enabled in the instance of the library that you're using, of course), it does not have an actual JSON type. Instead, use TEXT columns to hold JSON text like you would any other string.

More reading on the data types that sqlite supports and how unknown types are treated in table defintions.

Related