mirror of
https://github.com/chaisql/chai.git
synced 2025-10-05 15:46:55 +08:00
db: introduce row type
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/genjidb/genji/internal/query/statement"
|
||||
"github.com/genjidb/genji/internal/sql/parser"
|
||||
"github.com/genjidb/genji/internal/stream"
|
||||
"github.com/genjidb/genji/internal/stream/docs"
|
||||
"github.com/genjidb/genji/internal/stream/path"
|
||||
"github.com/genjidb/genji/internal/stream/rows"
|
||||
"github.com/genjidb/genji/internal/stream/table"
|
||||
"github.com/genjidb/genji/internal/testutil"
|
||||
"github.com/genjidb/genji/internal/testutil/assert"
|
||||
@@ -24,8 +24,8 @@ func TestParserInsert(t *testing.T) {
|
||||
expected *stream.Stream
|
||||
fails bool
|
||||
}{
|
||||
{"Documents", `INSERT INTO test VALUES {a: 1, "b": "foo", c: 'bar', d: 1 = 1, e: {f: "baz"}}`,
|
||||
stream.New(docs.Emit(
|
||||
{"Objects", `INSERT INTO test VALUES {a: 1, "b": "foo", c: 'bar', d: 1 = 1, e: {f: "baz"}}`,
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{SelfReferenced: true, Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.IntegerValue(1)},
|
||||
{K: "b", V: testutil.TextValue("foo")},
|
||||
@@ -40,8 +40,8 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(stream.Discard()),
|
||||
false},
|
||||
{"Documents / Multiple", `INSERT INTO test VALUES {"a": 'a', b: -2.3}, {a: 1, d: true}`,
|
||||
stream.New(docs.Emit(
|
||||
{"Objects / Multiple", `INSERT INTO test VALUES {"a": 'a', b: -2.3}, {a: 1, d: true}`,
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{SelfReferenced: true, Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("a")},
|
||||
{K: "b", V: testutil.DoubleValue(-2.3)},
|
||||
@@ -52,8 +52,8 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(stream.Discard()),
|
||||
false},
|
||||
{"Documents / Positional Param", "INSERT INTO test VALUES ?, ?",
|
||||
stream.New(docs.Emit(
|
||||
{"Objects / Positional Param", "INSERT INTO test VALUES ?, ?",
|
||||
stream.New(rows.Emit(
|
||||
expr.PositionalParam(1),
|
||||
expr.PositionalParam(2),
|
||||
)).
|
||||
@@ -61,8 +61,8 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(stream.Discard()),
|
||||
false},
|
||||
{"Documents / Named Param", "INSERT INTO test VALUES $foo, $bar",
|
||||
stream.New(docs.Emit(
|
||||
{"Objects / Named Param", "INSERT INTO test VALUES $foo, $bar",
|
||||
stream.New(rows.Emit(
|
||||
expr.NamedParam("foo"),
|
||||
expr.NamedParam("bar"),
|
||||
)).
|
||||
@@ -71,7 +71,7 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(stream.Discard()),
|
||||
false},
|
||||
{"Values / With fields", "INSERT INTO test (a, b) VALUES ('c', 'd')",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -84,7 +84,7 @@ func TestParserInsert(t *testing.T) {
|
||||
{"Values / With too many values", "INSERT INTO test (a, b) VALUES ('c', 'd', 'e')",
|
||||
nil, true},
|
||||
{"Values / Multiple", "INSERT INTO test (a, b) VALUES ('c', 'd'), ('e', 'f')",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -99,7 +99,7 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(stream.Discard()),
|
||||
false},
|
||||
{"Values / Returning", "INSERT INTO test (a, b) VALUES ('c', 'd') RETURNING *, a, b as B, c",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -107,14 +107,14 @@ func TestParserInsert(t *testing.T) {
|
||||
)).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(docs.Project(expr.Wildcard{}, testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b", "B"), testutil.ParseNamedExpr(t, "c"))),
|
||||
Pipe(rows.Project(expr.Wildcard{}, testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b", "B"), testutil.ParseNamedExpr(t, "c"))),
|
||||
false},
|
||||
{"Values / With fields / Wrong values", "INSERT INTO test (a, b) VALUES {a: 1}, ('e', 'f')",
|
||||
nil, true},
|
||||
{"Values / Without fields / Wrong values", "INSERT INTO test VALUES {a: 1}, ('e', 'f')",
|
||||
nil, true},
|
||||
{"Values / ON CONFLICT DO NOTHING", "INSERT INTO test (a, b) VALUES ('c', 'd') ON CONFLICT DO NOTHING RETURNING *",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -125,7 +125,7 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")),
|
||||
false},
|
||||
{"Values / ON CONFLICT IGNORE", "INSERT INTO test (a, b) VALUES ('c', 'd') ON CONFLICT IGNORE RETURNING *",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -135,7 +135,7 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")),
|
||||
false},
|
||||
{"Values / ON CONFLICT DO REPLACE", "INSERT INTO test (a, b) VALUES ('c', 'd') ON CONFLICT DO REPLACE RETURNING *",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -146,7 +146,7 @@ func TestParserInsert(t *testing.T) {
|
||||
Pipe(table.Insert("test")),
|
||||
false},
|
||||
{"Values / ON CONFLICT REPLACE", "INSERT INTO test (a, b) VALUES ('c', 'd') ON CONFLICT REPLACE RETURNING *",
|
||||
stream.New(docs.Emit(
|
||||
stream.New(rows.Emit(
|
||||
&expr.KVPairs{Pairs: []expr.KVPair{
|
||||
{K: "a", V: testutil.TextValue("c")},
|
||||
{K: "b", V: testutil.TextValue("d")},
|
||||
@@ -168,7 +168,7 @@ func TestParserInsert(t *testing.T) {
|
||||
false},
|
||||
{"Select / Without fields / With projection", "INSERT INTO test SELECT a, b FROM foo",
|
||||
stream.New(table.Scan("foo")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b"))).
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b"))).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(stream.Discard()),
|
||||
@@ -182,7 +182,7 @@ func TestParserInsert(t *testing.T) {
|
||||
false},
|
||||
{"Select / With fields / With projection", "INSERT INTO test (a, b) SELECT a, b FROM foo",
|
||||
stream.New(table.Scan("foo")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b"))).
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "a"), testutil.ParseNamedExpr(t, "b"))).
|
||||
Pipe(path.PathsRename("a", "b")).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(table.Insert("test")).
|
||||
@@ -190,7 +190,7 @@ func TestParserInsert(t *testing.T) {
|
||||
false},
|
||||
{"Select / With fields / With projection / different fields", "INSERT INTO test (a, b) SELECT c, d FROM foo",
|
||||
stream.New(table.Scan("foo")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(path.PathsRename("a", "b")).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(table.Insert("test")).
|
||||
@@ -198,20 +198,20 @@ func TestParserInsert(t *testing.T) {
|
||||
false},
|
||||
{"Select / With fields / With projection / different fields / Returning", "INSERT INTO test (a, b) SELECT c, d FROM foo RETURNING a",
|
||||
stream.New(table.Scan("foo")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(path.PathsRename("a", "b")).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "a"))),
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "a"))),
|
||||
false},
|
||||
{"Select / With fields / With projection / different fields / On conflict / Returning", "INSERT INTO test (a, b) SELECT c, d FROM foo ON CONFLICT DO NOTHING RETURNING a",
|
||||
stream.New(table.Scan("foo")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "c"), testutil.ParseNamedExpr(t, "d"))).
|
||||
Pipe(path.PathsRename("a", "b")).
|
||||
Pipe(table.Validate("test")).
|
||||
Pipe(stream.OnConflict(nil)).
|
||||
Pipe(table.Insert("test")).
|
||||
Pipe(docs.Project(testutil.ParseNamedExpr(t, "a"))),
|
||||
Pipe(rows.Project(testutil.ParseNamedExpr(t, "a"))),
|
||||
false},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user