Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support filtering table definitions #39

Merged
merged 12 commits into from
Oct 10, 2022
8 changes: 5 additions & 3 deletions builder/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type ColumnMapper func(*rel.Column) (string, int, int)
type DefinitionFilter func(table rel.Table, def rel.TableDefinition) bool
type DefinitionFilter func(table rel.Table, def rel.TableDefinition) (bool, string)

// Table builder.
type Table struct {
Expand Down Expand Up @@ -244,10 +244,12 @@ func (t Table) definitions(table rel.Table) []rel.TableDefinition {
result := []rel.TableDefinition{}

for _, def := range table.Definitions {
if t.DefinitionFilter(table, def) {
ok, reason := t.DefinitionFilter(table, def)

if ok {
result = append(result, def)
} else {
log.Print("[REL] An unsupported table definition has been excluded")
log.Print("[REL] An unsupported table definition has been excluded: " + reason)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it be simpler if we just use: log.Printf("[REL] ....: %T", def)?

}
}

Expand Down
9 changes: 3 additions & 6 deletions builder/table_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package builder

import (
"log"
"testing"
"time"

Expand Down Expand Up @@ -137,17 +136,15 @@ func TestTable_Build(t *testing.T) {

func TestTable_BuildWithDefinitionFilter(t *testing.T) {
var (
definitionFilter = func(table rel.Table, def rel.TableDefinition) bool {
definitionFilter = func(table rel.Table, def rel.TableDefinition) (bool, string) {
_, ok := def.(rel.Key)
// https://www.sqlite.org/omitted.html
// > Only the RENAME TABLE, ADD COLUMN, RENAME COLUMN, and DROP COLUMN variants of the ALTER TABLE command are supported.
if ok && table.Op == rel.SchemaAlter {
log.Print("[REL] Adapter does not support adding keys when modifying tables")

return false
return false, "adapter does not support adding keys when modifying tables"
}

return true
return true, ""
}
tableBuilder = Table{
BufferFactory: BufferFactory{InlineValues: true, BoolTrueValue: "true", BoolFalseValue: "false", Quoter: Quote{IDPrefix: "`", IDSuffix: "`", IDSuffixEscapeChar: "`", ValueQuote: "'", ValueQuoteEscapeChar: "'"}},
Expand Down