Repository: go-jet/jet (go)

Issue:
LIMIT ... for UPDATE statements
**Is your feature request related to a problem? Please describe.**

There does not seem to be `LIMIT ...` available for `UPDATE` statements. Is this intentional or is this something that could be added in the future?

**Describe the solution you'd like**

Being able to specify `LIMIT ...` on `UPDATE` statements to limit the updated rows.

Pull request:
feature: Add support for LIMIT query in UPDATE for sql/sqlite
Closes #448 

Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index a36737b..d3b1ee8 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -140,20 +140,13 @@ jobs:
 
       - run:
           name: Running tests
-          command:  gotestsum --junitfile $TEST_RESULTS/report.xml --format testname   -- -tags postgres -coverprofile=cover.out  -covermode=atomic -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/...,github.com/go-jet/jet/v2/stmtcache/... ./...
+          command:  gotestsum --junitfile $TEST_RESULTS/report.xml --format testname   -- -coverprofile=cover.out  -covermode=atomic -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/...,github.com/go-jet/jet/v2/stmtcache/... ./...
 
       - run:
           name: Running tests with statement caching enabled
-          command: JET_TESTS_WITH_STMT_CACHE=true go test -tags postgres -v ./tests/...
+          command: JET_TESTS_WITH_STMT_CACHE=true go test -v ./tests/...
 
       # run mariaDB and cockroachdb tests. No need to collect coverage, because coverage is already included with mysql and postgres tests
-      - run:
-          name: Jet generate mariadb and cockroachdb
-          command: |
-            cd tests
-            make jet-gen-mariadb
-            make jet-gen-cockroach
-
       - run: MY_SQL_SOURCE=MariaDB go test -v  ./tests/mysql/
       - run: PG_SOURCE=COCKROACH_DB go test -v ./tests/postgres/
 
diff --git a/generator/metadata/table_meta_data.go b/generator/metadata/table_meta_data.go
index 9533988..1d56bc0 100644
--- a/generator/metadata/table_meta_data.go
+++ b/generator/metadata/table_meta_data.go
@@ -21,16 +21,3 @@ func (t Table) MutableColumns() []Column {
 
 	return ret
 }
-
-// DefaultColumns returns list of columns with default values set for table
-func (t Table) DefaultColumns() []Column {
-	var ret []Column
-
-	for _, column := range t.Columns {
-		if column.HasDefault {
-			ret = append(ret, column)
-		}
-	}
-
-	return ret
-}
diff --git a/generator/mysql/query_set.go b/generator/mysql/query_set.go
index 14da5aa..6dc2714 100644
--- a/generator/mysql/query_set.go
+++ b/generator/mysql/query_set.go
@@ -18,7 +18,7 @@ func (m mySqlQuerySet) GetTablesMetaData(db *sql.DB, schemaName string, tableTyp
 SELECT
 		t.table_name as "table.name",
 		col.COLUMN_NAME AS "column.Name",
-		col.COLUMN_DEFAULT IS NOT NULL AND t.table_type != 'VIEW' as "column.HasDefault",
+		col.COLUMN_DEFAULT IS NOT NULL as "column.HasDefault",
 		col.IS_NULLABLE = "YES" AS "column.IsNullable",
 		col.COLUMN_COMMENT AS "column.Comment",
 		COALESCE(pk.IsPrimaryKey, 0) AS "column.IsPrimaryKey",
diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go
index 03c5b83..be3d2f6 100644
--- a/generator/template/file_templates.go
+++ b/generator/template/file_templates.go
@@ -33,7 +33,6 @@ type {{structImplName}} struct {
 
 	AllColumns     {{dialect.PackageName}}.ColumnList
 	MutableColumns {{dialect.PackageName}}.ColumnList
-	DefaultColumns {{dialect.PackageName}}.ColumnList
 }
 
 type {{tableTemplate.TypeName}} struct {
@@ -79,7 +78,6 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
 {{- end}}
 		allColumns     = {{dialect.PackageName}}.ColumnList{ {{columnList .Columns}} }
 		mutableColumns = {{dialect.PackageName}}.ColumnList{ {{columnList .MutableColumns}} }
-		defaultColumns = {{dialect.PackageName}}.ColumnList{ {{columnList .DefaultColumns}} }
 	)
 
 	return {{structImplName}}{
@@ -95,7 +93,6 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
diff --git a/generator/template/sql_builder_template.go b/generator/template/sql_builder_template.go
index cfd40aa..a72e8e9 100644
--- a/generator/template/sql_builder_template.go
+++ b/generator/template/sql_builder_template.go
@@ -136,7 +136,7 @@ type TableSQLBuilderColumn struct {
 	Type string
 }
 
-var reservedKeywords = []string{"TableName", "Table", "SchemaName", "Alias", "AllColumns", "MutableColumns", "DefaultColumns"}
+var reservedKeywords = []string{"TableName", "Table", "SchemaName", "Alias", "AllColumns", "MutableColumns"}
 
 func renameIfReserved(name string) string {
 	if slices.Contains(reservedKeywords, name) {
diff --git a/mysql/update_statement.go b/mysql/update_statement.go
index b0acaef..d47378a 100644
--- a/mysql/update_statement.go
+++ b/mysql/update_statement.go
@@ -12,6 +12,7 @@ type UpdateStatement interface {
 	MODEL(data interface{}) UpdateStatement
 
 	WHERE(expression BoolExpression) UpdateStatement
+	LIMIT(limit int64) UpdateStatement
 }
 
 type updateStatementImpl struct {
@@ -21,6 +22,7 @@ type updateStatementImpl struct {
 	Set    jet.SetClause
 	SetNew jet.SetClauseNew
 	Where  jet.ClauseWhere
+	Limit  jet.ClauseLimit
 }
 
 func newUpdateStatement(table Table, columns []jet.Column) UpdateStatement {
@@ -29,11 +31,13 @@ func newUpdateStatement(table Table, columns []jet.Column) UpdateStatement {
 		&update.Update,
 		&update.Set,
 		&update.SetNew,
-		&update.Where)
+		&update.Where,
+		&update.Limit)
 
 	update.Update.Table = table
 	update.Set.Columns = columns
 	update.Where.Mandatory = true
+	update.Limit.Count = -1 // Initialize to -1 to indicate no LIMIT
 
 	return update
 }
@@ -67,3 +71,11 @@ func (u *updateStatementImpl) WHERE(expression BoolExpression) UpdateStatement {
 	u.Where.Condition = expression
 	return u
 }
+
+func (u *updateStatementImpl) LIMIT(limit int64) UpdateStatement {
+	if _, isJoinTable := u.Update.Table.(*joinTable); isJoinTable {
+		panic("jet: MySQL does not support LIMIT with multi-table UPDATE statements")
+	}
+	u.Limit.Count = limit
+	return u
+}


Test patch:
diff --git a/generator/template/sql_builder_template_test.go b/generator/template/sql_builder_template_test.go
index b980a60..25834fc 100644
--- a/generator/template/sql_builder_template_test.go
+++ b/generator/template/sql_builder_template_test.go
@@ -22,7 +22,6 @@ func TestColumnRenameReserved(t *testing.T) {
 		{col: "Alias", want: "Alias_"},
 		{col: "AllColumns", want: "AllColumns_"},
 		{col: "MutableColumns", want: "MutableColumns_"},
-		{col: "DefaultColumns", want: "DefaultColumns_"},
 		{col: "OtherColumn", want: "OtherColumn"},
 	}
 
diff --git a/mysql/update_statement_test.go b/mysql/update_statement_test.go
index f5284a7..5c9be2f 100644
--- a/mysql/update_statement_test.go
+++ b/mysql/update_statement_test.go
@@ -6,6 +6,21 @@ import (
 	"testing"
 )
 
+func TestUpdateWithLimit(t *testing.T) {
+	expectedSQL := `
+UPDATE db.table1
+SET col_int = ?
+WHERE table1.col_int >= ?
+LIMIT ?;
+`
+	stmt := table1.UPDATE(table1ColInt).
+		SET(1).
+		WHERE(table1ColInt.GT_EQ(Int(33))).
+		LIMIT(5)
+
+	assertStatementSql(t, stmt, expectedSQL, 1, int64(33), int64(5))
+}
+
 func TestUpdateWithOneValue(t *testing.T) {
 	expectedSQL := `
 UPDATE db.table1
@@ -69,11 +84,26 @@ func TestUpdateReservedWorldColumn(t *testing.T) {
 					Load: "foo",
 				},
 			).
-			WHERE(loadColumn.EQ(String("bar"))), strings.Replace(`
+			WHERE(loadColumn.EQ(String("bar"))).
+			LIMIT(0),
+		strings.Replace(`
 UPDATE db.table1
 SET ''Load'' = ?
-WHERE ''Load'' = ?;
-`, "''", "`", -1), "foo", "bar")
+WHERE ''Load'' = ?
+LIMIT ?;
+`, "''", "`", -1), "foo", "bar", int64(0))
+}
+
+func LimitPanicStatement() {
+	joinedTable := table1.INNER_JOIN(table2, table1Col1.EQ(table2Col3))
+	joinedTable.UPDATE(table1ColInt).
+		SET(1).
+		WHERE(table1ColInt.GT_EQ(Int(33))).
+		LIMIT(5)
+}
+
+func TestUpdateWithMultiTableAndLimit(t *testing.T) {
+	assertPanicErr(t, func() { LimitPanicStatement() }, "jet: MySQL does not support LIMIT with multi-table UPDATE statements")
 }
 
 func TestInvalidInputs(t *testing.T) {
diff --git a/tests/Makefile b/tests/Makefile
index 6ea27b6..43a8d66 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -14,7 +14,7 @@ checkout-latest-testdata: checkout-testdata
 # database with testdata retrieved in previous step.
 # On the first run this action might take couple of minutes. Docker temp data are stored in .docker directory.
 docker-compose-up:
-	docker compose up
+	docker-compose up
 
 init-all:
 	go run ./init/init.go -testsuite all
@@ -74,4 +74,4 @@ jet-gen-cockroach:
 
 # docker-compose-cleanup will stop and remove test containers, volumes, and images.
 cleanup:
-	docker compose down --volumes
+	docker-compose down --volumes
diff --git a/tests/mysql/generator_test.go b/tests/mysql/generator_test.go
index 800de18..2a915a5 100644
--- a/tests/mysql/generator_test.go
+++ b/tests/mysql/generator_test.go
@@ -260,7 +260,6 @@ type linkTable struct {
 
 	AllColumns     mysql.ColumnList
 	MutableColumns mysql.ColumnList
-	DefaultColumns mysql.ColumnList
 }
 
 type LinkTable struct {
@@ -304,7 +303,6 @@ func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
 		DescriptionColumn = mysql.StringColumn("description")
 		allColumns        = mysql.ColumnList{IDColumn, URLColumn, NameColumn, DescriptionColumn}
 		mutableColumns    = mysql.ColumnList{URLColumn, NameColumn, DescriptionColumn}
-		defaultColumns    = mysql.ColumnList{DescriptionColumn}
 	)
 
 	return linkTable{
@@ -318,7 +316,6 @@ func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `)
@@ -378,7 +375,6 @@ type actorTable struct {
 
 	AllColumns     mysql.ColumnList
 	MutableColumns mysql.ColumnList
-	DefaultColumns mysql.ColumnList
 }
 
 type ActorTable struct {
@@ -422,7 +418,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 		LastUpdateColumn = mysql.TimestampColumn("last_update")
 		allColumns       = mysql.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn}
 		mutableColumns   = mysql.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn}
-		defaultColumns   = mysql.ColumnList{LastUpdateColumn}
 	)
 
 	return actorTable{
@@ -436,7 +431,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -522,7 +516,6 @@ type actorInfoTable struct {
 
 	AllColumns     mysql.ColumnList
 	MutableColumns mysql.ColumnList
-	DefaultColumns mysql.ColumnList
 }
 
 type ActorInfoTable struct {
@@ -566,7 +559,6 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
 		FilmInfoColumn  = mysql.StringColumn("film_info")
 		allColumns      = mysql.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
 		mutableColumns  = mysql.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
-		defaultColumns  = mysql.ColumnList{}
 	)
 
 	return actorInfoTable{
@@ -580,7 +572,6 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
diff --git a/tests/mysql/update_test.go b/tests/mysql/update_test.go
index cf9a7ea..2376bcb 100644
--- a/tests/mysql/update_test.go
+++ b/tests/mysql/update_test.go
@@ -2,10 +2,11 @@ package mysql
 
 import (
 	"context"
-	"github.com/go-jet/jet/v2/qrm"
 	"testing"
 	"time"
 
+	"github.com/go-jet/jet/v2/qrm"
+
 	"github.com/stretchr/testify/require"
 
 	"github.com/go-jet/jet/v2/internal/testutils"
@@ -285,3 +286,56 @@ WHERE link.name = 'Bing';
 		require.NoError(t, err)
 	})
 }
+
+func TestUpdateWithLimit(t *testing.T) {
+	t.Run("single table update with limit", func(t *testing.T) {
+		stmt := Link.
+			UPDATE(Link.Name).
+			SET(String("Updated Link")).
+			WHERE(Link.Name.NOT_EQ(String(""))).
+			LIMIT(2)
+
+		testutils.AssertDebugStatementSql(t, stmt, `
+UPDATE test_sample.link
+SET name = 'Updated Link'
+WHERE link.name != ''
+LIMIT 2;
+`)
+
+		testutils.ExecuteInTxAndRollback(t, db, func(tx qrm.DB) {
+			// Execute update
+			testutils.AssertExec(t, stmt, tx)
+			requireLogged(t, stmt)
+
+			// Verify only 2 rows were updated
+			var updatedLinks []model.Link
+			err := Link.
+				SELECT(Link.AllColumns).
+				WHERE(Link.Name.EQ(String("Updated Link"))).
+				Query(tx, &updatedLinks)
+
+			require.NoError(t, err)
+			require.Equal(t, 2, len(updatedLinks))
+		})
+	})
+
+	t.Run("multi-table update with limit should panic", func(t *testing.T) {
+		defer func() {
+			r := recover()
+			require.NotNil(t, r)
+			require.Equal(t, "jet: MySQL does not support LIMIT with multi-table UPDATE statements", r)
+		}()
+
+		joinedTable := Link.
+			INNER_JOIN(Link2, Link.Name.EQ(Link2.Name))
+
+		stmt := joinedTable.
+			UPDATE(Link.Name).
+			SET(String("Updated Link")).
+			WHERE(Link.Name.NOT_EQ(String(""))).
+			LIMIT(2)
+
+		// Statement construction itself should panic
+		_ = stmt
+	})
+}
diff --git a/tests/postgres/generator_test.go b/tests/postgres/generator_test.go
index 005e703..93fb9c3 100644
--- a/tests/postgres/generator_test.go
+++ b/tests/postgres/generator_test.go
@@ -520,7 +520,6 @@ type actorTable struct {
 
 	AllColumns     postgres.ColumnList
 	MutableColumns postgres.ColumnList
-	DefaultColumns postgres.ColumnList
 }
 
 type ActorTable struct {
@@ -564,7 +563,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 		LastUpdateColumn = postgres.TimestampColumn("last_update")
 		allColumns       = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn}
 		mutableColumns   = postgres.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn}
-		defaultColumns   = postgres.ColumnList{ActorIDColumn}
 	)
 
 	return actorTable{
@@ -578,7 +576,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -663,7 +660,6 @@ type actorInfoTable struct {
 
 	AllColumns     postgres.ColumnList
 	MutableColumns postgres.ColumnList
-	DefaultColumns postgres.ColumnList
 }
 
 type ActorInfoTable struct {
@@ -707,7 +703,6 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
 		FilmInfoColumn  = postgres.StringColumn("film_info")
 		allColumns      = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
 		mutableColumns  = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
-		defaultColumns  = postgres.ColumnList{}
 	)
 
 	return actorInfoTable{
@@ -721,7 +716,6 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -1017,7 +1011,6 @@ type allTypesTable struct {
 
 	AllColumns     postgres.ColumnList
 	MutableColumns postgres.ColumnList
-	DefaultColumns postgres.ColumnList
 }
 
 type AllTypesTable struct {
@@ -1120,7 +1113,6 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
 		MoodColumn                 = postgres.StringColumn("mood")
 		allColumns                 = postgres.ColumnList{SmallIntPtrColumn, SmallIntColumn, IntegerPtrColumn, IntegerColumn, BigIntPtrColumn, BigIntColumn, DecimalPtrColumn, DecimalColumn, NumericPtrColumn, NumericColumn, RealPtrColumn, RealColumn, DoublePrecisionPtrColumn, DoublePrecisionColumn, SmallserialColumn, SerialColumn, BigserialColumn, VarCharPtrColumn, VarCharColumn, CharPtrColumn, CharColumn, TextPtrColumn, TextColumn, ByteaPtrColumn, ByteaColumn, TimestampzPtrColumn, TimestampzColumn, TimestampPtrColumn, TimestampColumn, DatePtrColumn, DateColumn, TimezPtrColumn, TimezColumn, TimePtrColumn, TimeColumn, IntervalPtrColumn, IntervalColumn, BooleanPtrColumn, BooleanColumn, PointPtrColumn, BitPtrColumn, BitColumn, BitVaryingPtrColumn, BitVaryingColumn, TsvectorPtrColumn, TsvectorColumn, UUIDPtrColumn, UUIDColumn, XMLPtrColumn, XMLColumn, JSONPtrColumn, JSONColumn, JsonbPtrColumn, JsonbColumn, IntegerArrayPtrColumn, IntegerArrayColumn, TextArrayPtrColumn, TextArrayColumn, JsonbArrayColumn, TextMultiDimArrayPtrColumn, TextMultiDimArrayColumn, MoodPtrColumn, MoodColumn}
 		mutableColumns             = postgres.ColumnList{SmallIntPtrColumn, SmallIntColumn, IntegerPtrColumn, IntegerColumn, BigIntPtrColumn, BigIntColumn, DecimalPtrColumn, DecimalColumn, NumericPtrColumn, NumericColumn, RealPtrColumn, RealColumn, DoublePrecisionPtrColumn, DoublePrecisionColumn, SmallserialColumn, SerialColumn, BigserialColumn, VarCharPtrColumn, VarCharColumn, CharPtrColumn, CharColumn, TextPtrColumn, TextColumn, ByteaPtrColumn, ByteaColumn, TimestampzPtrColumn, TimestampzColumn, TimestampPtrColumn, TimestampColumn, DatePtrColumn, DateColumn, TimezPtrColumn, TimezColumn, TimePtrColumn, TimeColumn, IntervalPtrColumn, IntervalColumn, BooleanPtrColumn, BooleanColumn, PointPtrColumn, BitPtrColumn, BitColumn, BitVaryingPtrColumn, BitVaryingColumn, TsvectorPtrColumn, TsvectorColumn, UUIDPtrColumn, UUIDColumn, XMLPtrColumn, XMLColumn, JSONPtrColumn, JSONColumn, JsonbPtrColumn, JsonbColumn, IntegerArrayPtrColumn, IntegerArrayColumn, TextArrayPtrColumn, TextArrayColumn, JsonbArrayColumn, TextMultiDimArrayPtrColumn, TextMultiDimArrayColumn, MoodPtrColumn, MoodColumn}
-		defaultColumns             = postgres.ColumnList{SmallIntColumn, IntegerColumn, BigIntColumn, DecimalColumn, NumericColumn, RealColumn, DoublePrecisionColumn, SmallserialColumn, SerialColumn, BigserialColumn, VarCharColumn, CharColumn, TextColumn, ByteaColumn, TimestampzColumn, TimestampColumn, DateColumn, TimezColumn, TimeColumn, IntervalColumn, BooleanColumn, BitColumn, BitVaryingColumn, TsvectorColumn, UUIDColumn, XMLColumn, JSONColumn, JsonbColumn, IntegerArrayColumn, TextArrayColumn, JsonbArrayColumn, TextMultiDimArrayColumn, MoodColumn}
 	)
 
 	return allTypesTable{
@@ -1193,7 +1185,6 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -1227,7 +1218,6 @@ type sampleRangesTable struct {
 
 	AllColumns     postgres.ColumnList
 	MutableColumns postgres.ColumnList
-	DefaultColumns postgres.ColumnList
 }
 
 type SampleRangesTable struct {
@@ -1273,7 +1263,6 @@ func newSampleRangesTableImpl(schemaName, tableName, alias string) sampleRangesT
 		NumRangeColumn        = postgres.NumericRangeColumn("num_range")
 		allColumns            = postgres.ColumnList{DateRangeColumn, TimestampRangeColumn, TimestampzRangeColumn, Int4RangeColumn, Int8RangeColumn, NumRangeColumn}
 		mutableColumns        = postgres.ColumnList{DateRangeColumn, TimestampRangeColumn, TimestampzRangeColumn, Int4RangeColumn, Int8RangeColumn, NumRangeColumn}
-		defaultColumns        = postgres.ColumnList{DateRangeColumn, TimestampRangeColumn, TimestampzRangeColumn, Int4RangeColumn, Int8RangeColumn, NumRangeColumn}
 	)
 
 	return sampleRangesTable{
@@ -1289,7 +1278,6 @@ func newSampleRangesTableImpl(schemaName, tableName, alias string) sampleRangesT
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -1322,7 +1310,6 @@ type linkTable struct {
 
 	AllColumns     postgres.ColumnList
 	MutableColumns postgres.ColumnList
-	DefaultColumns postgres.ColumnList
 }
 
 type LinkTable struct {
@@ -1366,7 +1353,6 @@ func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
 		DescriptionColumn = postgres.StringColumn("description")
 		allColumns        = postgres.ColumnList{IDColumn, URLColumn, NameColumn, DescriptionColumn}
 		mutableColumns    = postgres.ColumnList{URLColumn, NameColumn, DescriptionColumn}
-		defaultColumns    = postgres.ColumnList{IDColumn}
 	)
 
 	return linkTable{
@@ -1380,7 +1366,6 @@ func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
diff --git a/tests/postgres/range_test.go b/tests/postgres/range_test.go
index b2ef54c..8742fd8 100644
--- a/tests/postgres/range_test.go
+++ b/tests/postgres/range_test.go
@@ -1,6 +1,3 @@
-//go:build postgres
-// +build postgres
-
 package postgres
 
 import (
@@ -15,7 +12,7 @@ import (
 
 	. "github.com/go-jet/jet/v2/postgres"
 	"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/test_sample/model"
-	"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/test_sample/table"
+	. "github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/test_sample/table"
 )
 
 func TestRangeTableSelect(t *testing.T) {
@@ -35,40 +32,40 @@ func TestRangeTableSelect(t *testing.T) {
 	)
 
 	query := SELECT(
-		table.SampleRanges.AllColumns,
-
-		table.SampleRanges.Int4Range.EQ(table.SampleRanges.Int4Range).AS("sample.int4eq"),
-		table.SampleRanges.Int8Range.EQ(int8Range).AS("sample.int8eq"),
-		table.SampleRanges.Int4Range.NOT_EQ(int4Range).AS("sample.int4neq"),
-		table.SampleRanges.NumRange.LT(numRange).IS_TRUE().AS("sample.num_lt"),
-		table.SampleRanges.DateRange.LT_EQ(dateRange).IS_FALSE().AS("sample.date_lteq"),
-		table.SampleRanges.TimestampRange.GT(tsRange).AS("sample.ts_gt"),
-		table.SampleRanges.TimestampzRange.GT_EQ(tstzRange).AS("sample.tstz_gteq"),
-		table.SampleRanges.Int4Range.CONTAINS(Int32(22)).AS("sample.int4cont"),
-		table.SampleRanges.Int8Range.CONTAINS(Int64(75364)).AS("sample.int8cont"),
-		table.SampleRanges.Int8Range.CONTAINS_RANGE(int8Range).AS("sample.int8cont_range"),
-		table.SampleRanges.NumRange.OVERLAP(numRange).AS("sample.num_overlap"),
-		table.SampleRanges.DateRange.UNION(dateRange).AS("sample.date_union"),
-		table.SampleRanges.TimestampRange.INTERSECTION(tsRange).AS("sample.ts_ints"),
-		table.SampleRanges.TimestampzRange.DIFFERENCE(tstzRange).AS("sample.tstz_diff"),
-		table.SampleRanges.Int4Range.UPPER_BOUND().ADD(Int(5)).AS("sample.int4_upper"),
-		table.SampleRanges.Int8Range.LOWER_BOUND().SUB(Int(12)).AS("sample.int8_lower"),
-		LOWER_BOUND[DateExpression](table.SampleRanges.DateRange),
-		UPPER_BOUND[NumericExpression](table.SampleRanges.NumRange).AS("sample.num_upper"),
-		table.SampleRanges.TimestampRange.UPPER_BOUND(),
-		table.SampleRanges.DateRange.IS_EMPTY().AS("sample.date_empty"),
-		table.SampleRanges.TimestampRange.LOWER_INC().AS("sample.ts_low_inc"),
-		table.SampleRanges.TimestampzRange.UPPER_INC().AS("sample.tstz_up_inc"),
-		table.SampleRanges.TimestampRange.LOWER_INF().AS("sample.ts_low_inf"),
-		table.SampleRanges.TimestampzRange.UPPER_INF().AS("sample.tstz_up_inf"),
+		SampleRanges.AllColumns,
+
+		SampleRanges.Int4Range.EQ(SampleRanges.Int4Range).AS("sample.int4eq"),
+		SampleRanges.Int8Range.EQ(int8Range).AS("sample.int8eq"),
+		SampleRanges.Int4Range.NOT_EQ(int4Range).AS("sample.int4neq"),
+		SampleRanges.NumRange.LT(numRange).IS_TRUE().AS("sample.num_lt"),
+		SampleRanges.DateRange.LT_EQ(dateRange).IS_FALSE().AS("sample.date_lteq"),
+		SampleRanges.TimestampRange.GT(tsRange).AS("sample.ts_gt"),
+		SampleRanges.TimestampzRange.GT_EQ(tstzRange).AS("sample.tstz_gteq"),
+		SampleRanges.Int4Range.CONTAINS(Int32(22)).AS("sample.int4cont"),
+		SampleRanges.Int8Range.CONTAINS(Int64(75364)).AS("sample.int8cont"),
+		SampleRanges.Int8Range.CONTAINS_RANGE(int8Range).AS("sample.int8cont_range"),
+		SampleRanges.NumRange.OVERLAP(numRange).AS("sample.num_overlap"),
+		SampleRanges.DateRange.UNION(dateRange).AS("sample.date_union"),
+		SampleRanges.TimestampRange.INTERSECTION(tsRange).AS("sample.ts_ints"),
+		SampleRanges.TimestampzRange.DIFFERENCE(tstzRange).AS("sample.tstz_diff"),
+		SampleRanges.Int4Range.UPPER_BOUND().ADD(Int(5)).AS("sample.int4_upper"),
+		SampleRanges.Int8Range.LOWER_BOUND().SUB(Int(12)).AS("sample.int8_lower"),
+		LOWER_BOUND[DateExpression](SampleRanges.DateRange),
+		UPPER_BOUND[NumericExpression](SampleRanges.NumRange).AS("sample.num_upper"),
+		SampleRanges.TimestampRange.UPPER_BOUND(),
+		SampleRanges.DateRange.IS_EMPTY().AS("sample.date_empty"),
+		SampleRanges.TimestampRange.LOWER_INC().AS("sample.ts_low_inc"),
+		SampleRanges.TimestampzRange.UPPER_INC().AS("sample.tstz_up_inc"),
+		SampleRanges.TimestampRange.LOWER_INF().AS("sample.ts_low_inf"),
+		SampleRanges.TimestampzRange.UPPER_INF().AS("sample.tstz_up_inf"),
 
 		RawInt4Range("'[1,2]'").EQ(int4Range),
 		RawInt8Range("int8range(15, 25)").EQ(int8Range),
 		RawNumRange("numrange(20.0, 30.0)").NOT_EQ(numRange),
 	).FROM(
-		table.SampleRanges,
+		SampleRanges,
 	).WHERE(
-		table.SampleRanges.DateRange.CONTAINS(Date(2023, 12, 12)),
+		SampleRanges.DateRange.CONTAINS(Date(2023, 12, 12)),
 	)
 
 	testutils.AssertStatementSql(t, query, `
@@ -210,10 +207,10 @@ func TestRangeSelectColumnsFromSubQuery(t *testing.T) {
 	skipForCockroachDB(t)
 
 	subQuery := SELECT(
-		table.SampleRanges.AllColumns,
-		table.SampleRanges.Int4Range.AS("range4"),
+		SampleRanges.AllColumns,
+		SampleRanges.Int4Range.AS("range4"),
 	).FROM(
-		table.SampleRanges,
+		SampleRanges,
 	).AsTable("sub_query")
 
 	int4Range := Int4RangeColumn("range4").From(subQuery)
@@ -263,7 +260,7 @@ FROM (
 func TestRangeTable_InsertColumn(t *testing.T) {
 	skipForCockroachDB(t)
 
-	insertQuery := table.SampleRanges.INSERT(table.SampleRanges.AllColumns).
+	insertQuery := SampleRanges.INSERT(SampleRanges.AllColumns).
 		VALUES(
 			DATE_RANGE(
 				Date(2010, 01, 01),
@@ -282,7 +279,7 @@ func TestRangeTable_InsertColumn(t *testing.T) {
 		).
 		MODEL(
 			sampleRangeRow,
-		).RETURNING(table.SampleRanges.AllColumns)
+		).RETURNING(SampleRanges.AllColumns)
 
 	expectedQuery := `
 INSERT INTO test_sample.sample_ranges (date_range, timestamp_range, timestampz_range, int4_range, int8_range, num_range)
@@ -310,10 +307,10 @@ func TestRangeTableUpdate(t *testing.T) {
 	skipForCockroachDB(t)
 
 	t.Run("using model", func(t *testing.T) {
-		stmt := table.SampleRanges.UPDATE(table.SampleRanges.AllColumns).
+		stmt := SampleRanges.UPDATE(SampleRanges.AllColumns).
 			MODEL(sampleRangeRow).
-			WHERE(table.SampleRanges.TimestampRange.LOWER_INF().IS_FALSE()).
-			RETURNING(table.SampleRanges.AllColumns)
+			WHERE(SampleRanges.TimestampRange.LOWER_INF().IS_FALSE()).
+			RETURNING(SampleRanges.AllColumns)
 
 		testutils.AssertStatementSql(t, stmt, `
 UPDATE test_sample.sample_ranges
@@ -338,13 +335,13 @@ RETURNING sample_ranges.date_range AS "sample_ranges.date_range",
 	})
 
 	t.Run("update using SET", func(t *testing.T) {
-		stmt := table.SampleRanges.UPDATE().
+		stmt := SampleRanges.UPDATE().
 			SET(
-				table.SampleRanges.Int4Range.SET(INT4_RANGE(Int32(-12), Int32(78))),
-				table.SampleRanges.Int8Range.SET(INT8_RANGE(Int64(-1200), Int64(7800))),
+				SampleRanges.Int4Range.SET(INT4_RANGE(Int32(-12), Int32(78))),
+				SampleRanges.Int8Range.SET(INT8_RANGE(Int64(-1200), Int64(7800))),
 			).
 			WHERE(
-				table.SampleRanges.TimestampzRange.LOWER_BOUND().GT(Timestampz(2024, 2, 27, 0, 0, 0, 0, "UTC")),
+				SampleRanges.TimestampzRange.LOWER_BOUND().GT(Timestampz(2024, 2, 27, 0, 0, 0, 0, "UTC")),
 			)
 
 		testutils.AssertDebugStatementSql(t, stmt, `
diff --git a/tests/sqlite/generator_test.go b/tests/sqlite/generator_test.go
index f261d22..8a15568 100644
--- a/tests/sqlite/generator_test.go
+++ b/tests/sqlite/generator_test.go
@@ -185,7 +185,6 @@ type actorTable struct {
 
 	AllColumns     sqlite.ColumnList
 	MutableColumns sqlite.ColumnList
-	DefaultColumns sqlite.ColumnList
 }
 
 type ActorTable struct {
@@ -229,7 +228,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 		LastUpdateColumn = sqlite.TimestampColumn("last_update")
 		allColumns       = sqlite.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn}
 		mutableColumns   = sqlite.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn}
-		defaultColumns   = sqlite.ColumnList{LastUpdateColumn}
 	)
 
 	return actorTable{
@@ -243,7 +241,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `
@@ -310,7 +307,6 @@ type filmListTable struct {
 
 	AllColumns     sqlite.ColumnList
 	MutableColumns sqlite.ColumnList
-	DefaultColumns sqlite.ColumnList
 }
 
 type FilmListTable struct {
@@ -358,7 +354,6 @@ func newFilmListTableImpl(schemaName, tableName, alias string) filmListTable {
 		ActorsColumn      = sqlite.StringColumn("actors")
 		allColumns        = sqlite.ColumnList{FidColumn, TitleColumn, DescriptionColumn, CategoryColumn, PriceColumn, LengthColumn, RatingColumn, ActorsColumn}
 		mutableColumns    = sqlite.ColumnList{FidColumn, TitleColumn, DescriptionColumn, CategoryColumn, PriceColumn, LengthColumn, RatingColumn, ActorsColumn}
-		defaultColumns    = sqlite.ColumnList{}
 	)
 
 	return filmListTable{
@@ -376,7 +371,6 @@ func newFilmListTableImpl(schemaName, tableName, alias string) filmListTable {
 
 		AllColumns:     allColumns,
 		MutableColumns: mutableColumns,
-		DefaultColumns: defaultColumns,
 	}
 }
 `