Skip to content

Commit

Permalink
Do not mark auto increment columns as generated in SQLite driver
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo committed Apr 4, 2023
1 parent 39fdbd4 commit f14c359
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gen/bobgen-sqlite/driver/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (d driver) columns(ctx context.Context, schema, tableName string, tinfo []i
autoIncr := isPrimaryKeyInteger && (tableHasAutoIncr || nPkeys == 1)

// See: https://github.com/sqlite/sqlite/blob/91f621531dc1cb9ba5f6a47eb51b1de9ed8bdd07/src/pragma.c#L1165
column.Generated = autoIncr || colInfo.Hidden == 2 || colInfo.Hidden == 3
column.Generated = colInfo.Hidden == 2 || colInfo.Hidden == 3

if colInfo.DefaultValue.Valid {
column.Default = colInfo.DefaultValue.String
Expand Down
78 changes: 70 additions & 8 deletions gen/bobgen-sqlite/driver/sqlite.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand Down Expand Up @@ -143,7 +143,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand All @@ -156,10 +156,47 @@
"id"
]
},
"foreign_keys": [],
"foreign_keys": [
{
"name": "fk_autoinctest_0",
"columns": [
"id"
],
"foreign_table": "tags",
"foreign_columns": [
"id"
]
}
],
"unique": [],
"is_join_table": false,
"relationship": null
"relationship": [
{
"Name": "fk_autoinctest_0",
"ByJoinTable": false,
"Sides": [
{
"From": "autoinctest",
"To": "tags",
"Columns": null,
"FromColumns": [
"id"
],
"ToColumns": [
"id"
],
"FromWhere": null,
"ToWhere": null,
"ToKey": false,
"ToUnique": true,
"KeyNullable": false
}
],
"Ignored": false,
"NoReverse": false,
"Alias": ""
}
]
},
{
"key": "has_generated_columns",
Expand All @@ -172,7 +209,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand Down Expand Up @@ -249,7 +286,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand Down Expand Up @@ -326,7 +363,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand Down Expand Up @@ -367,7 +404,7 @@
"default": "auto_increment",
"comment": "",
"nullable": false,
"generated": true,
"generated": false,
"autoincr": false,
"domain_name": "",
"type": "int64",
Expand Down Expand Up @@ -951,6 +988,31 @@
"unique": [],
"is_join_table": false,
"relationship": [
{
"Name": "fk_autoinctest_0",
"ByJoinTable": false,
"Sides": [
{
"From": "tags",
"To": "autoinctest",
"Columns": null,
"FromColumns": [
"id"
],
"ToColumns": [
"id"
],
"FromWhere": null,
"ToWhere": null,
"ToKey": true,
"ToUnique": true,
"KeyNullable": false
}
],
"Ignored": false,
"NoReverse": false,
"Alias": ""
},
{
"Name": "fk_video_tags_0",
"ByJoinTable": false,
Expand Down
3 changes: 2 additions & 1 deletion gen/bobgen-sqlite/driver/testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ create table type_monsters (

-- all table defintions will not cause sqlite autoincrement primary key without rowid tables to be generated
create table autoinctest (
id INTEGER PRIMARY KEY NOT NULL
id INTEGER PRIMARY KEY NOT NULL,
FOREIGN KEY (id) REFERENCES tags (id) -- causes make sure id is included in getter
);

-- additional fields should not be marked as auto generated, when the AUTOINCREMENT keyword is present
Expand Down

0 comments on commit f14c359

Please sign in to comment.