2023-11-19 03:05:48 +03:00
|
|
|
//go:build sqlite_vtable && sqlite_fts5
|
|
|
|
|
|
|
|
package sqlite3_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-11-19 03:05:48 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/core/kind"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/sqlz"
|
|
|
|
"github.com/neilotoole/sq/libsq/source"
|
2024-01-25 09:29:55 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/source/drivertype"
|
2023-11-19 03:05:48 +03:00
|
|
|
"github.com/neilotoole/sq/testh"
|
|
|
|
"github.com/neilotoole/sq/testh/sakila"
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/testh/tu"
|
2023-11-19 03:05:48 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExtension_fts5(t *testing.T) {
|
|
|
|
const tblActorFts = "actor_fts"
|
|
|
|
|
|
|
|
th := testh.New(t)
|
|
|
|
src := th.Add(&source.Source{
|
|
|
|
Handle: "@fts",
|
2024-01-25 09:29:55 +03:00
|
|
|
Type: drivertype.SQLite,
|
2024-01-15 04:45:34 +03:00
|
|
|
Location: "sqlite3://" + tu.MustAbsFilepath("testdata", "sakila_fts5.db"),
|
2023-11-19 03:05:48 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
srcMeta, err := th.SourceMetadata(src)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, src.Handle, srcMeta.Handle)
|
|
|
|
tblMeta1 := srcMeta.Table(tblActorFts)
|
|
|
|
require.NotNil(t, tblMeta1)
|
|
|
|
require.Equal(t, tblActorFts, tblMeta1.Name)
|
|
|
|
require.Equal(t, sqlz.TableTypeVirtual, tblMeta1.TableType)
|
|
|
|
|
|
|
|
require.Equal(t, "actor_id", tblMeta1.Columns[0].Name)
|
|
|
|
require.Equal(t, "integer", tblMeta1.Columns[0].ColumnType)
|
|
|
|
require.Equal(t, "integer", tblMeta1.Columns[0].BaseType)
|
|
|
|
require.Equal(t, kind.Int, tblMeta1.Columns[0].Kind)
|
|
|
|
require.Equal(t, "first_name", tblMeta1.Columns[1].Name)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[1].ColumnType)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[1].BaseType)
|
|
|
|
require.Equal(t, kind.Text, tblMeta1.Columns[1].Kind)
|
|
|
|
require.Equal(t, "last_name", tblMeta1.Columns[2].Name)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[2].ColumnType)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[2].BaseType)
|
|
|
|
require.Equal(t, kind.Text, tblMeta1.Columns[2].Kind)
|
|
|
|
require.Equal(t, "last_update", tblMeta1.Columns[3].Name)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[3].ColumnType)
|
|
|
|
require.Equal(t, "text", tblMeta1.Columns[3].BaseType)
|
|
|
|
require.Equal(t, kind.Text, tblMeta1.Columns[3].Kind)
|
|
|
|
|
|
|
|
tblMeta2, err := th.TableMetadata(src, tblActorFts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tblActorFts, tblMeta2.Name)
|
|
|
|
require.Equal(t, sqlz.TableTypeVirtual, tblMeta2.TableType)
|
|
|
|
require.EqualValues(t, *tblMeta1, *tblMeta2)
|
|
|
|
|
|
|
|
// Verify that the (non-virtual) "actor" table has its type set correctly.
|
|
|
|
actorMeta1 := srcMeta.Table(sakila.TblActor)
|
|
|
|
actorMeta2, err := th.TableMetadata(src, sakila.TblActor)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, actorMeta1.TableType, sqlz.TableTypeTable)
|
|
|
|
require.Equal(t, *actorMeta1, *actorMeta2)
|
|
|
|
}
|