go-gorm / go-gorm/sqlite

SQLite strict tables

Open
#204 0 comments 4 reactions 1 assignee Claimed by @jinzhu View on GitHub
Dominant language
Go
Stars
231
Forks
217
PR merge metrics
No merged PRs in 30d

Description

## Describe the feature

With [strict tables](https://sqlite.org/stricttables.html), SQLite can enforce data type integrity that is not enforced otherwise. Without strict tables, the following works in SQLite:

```sql
CREATE TABLE user(id INTEGER);
INSERT into user VALUES ("YOLO!"); --- This works!
```

@anthonywritescode has a watchworthy [video about this](https://www.youtube.com/watch?v=VSiPVZcTQTo). Is it possible to enable strict tables in Gorm, somehow? I've tried to do `db.Set("gorm:table_options", "STRICT")`, but it seemingly has no effect. To inspect whether the table has been created strict, I run the following query:

```sql
select * from pragma_table_list
```

And if the `strict` column is set to `1`, it's a strict table. So far, I've not been successful in having Gorm create strict tables in SQLite. Do I need to create a custom SQLite `Dialector` for this?

## Motivation

Strict tables enable data integrity checks that are disabled by default.

Sorry for cross-posting this to https://github.com/go-gorm/gorm/discussions/7443, but I'm unsure whether this is a feature that belongs to Gorm or the SQLite driver/dialector.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.