mirror of
https://github.com/hanzoai/dbx.git
synced 2026-10-30 18:40:28 +00:00
Sync had its own spelling of CamelCase → snake_case, agreeing with the query builder's everywhere except after a digit: it broke a word only when the preceding character was a letter, so Fallback1Up became fallback1up in the CREATE TABLE and fallback1_up in every SELECT, INSERT and UPDATE. A table Sync created therefore carried a column no statement would ever name, and lacked the one every statement did — so a model worked against a database created some other way and failed against its own, reporting "table X has no column named Y" for a column its struct plainly declares. defaultFieldName is DefaultFieldMapFunc now, because there is one such name. Sync will add the correctly-named column to a table that already carries the other; the unused one is inert and can be dropped when convenient. Co-authored-by: Hanzo Dev <[email protected]>
20 lines
704 B
Go
20 lines
704 B
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
|
|
package dbx
|
|
|
|
import "testing"
|
|
|
|
// A table's columns and the statements that read them get their names from the
|
|
// same Go field, so the two derivations have to be one derivation. They were two,
|
|
// and they agreed everywhere except after a digit.
|
|
func TestSyncNamesColumnsTheWayQueriesDo(t *testing.T) {
|
|
for _, field := range []string{
|
|
"Fallback1Up", "Fallback2Up", "Owner", "ModelName", "CreatedTime",
|
|
"CostInPerMillion", "ID", "URLPath", "Line1Address", "X2Y",
|
|
} {
|
|
if got, want := defaultFieldName(field), DefaultFieldMapFunc(field); got != want {
|
|
t.Errorf("%s: Sync would create %q, statements would name %q", field, got, want)
|
|
}
|
|
}
|
|
}
|