Skip to content

Commit

Permalink
Add codegen for pgsparse.
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetrovykh committed Feb 10, 2024
1 parent f75993d commit e51a1b1
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 312 deletions.
4 changes: 4 additions & 0 deletions edgedb/codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"cal::date_duration": "edgedb.DateDuration",
"cfg::memory": "edgedb.ConfigMemory",
"ext::pgvector::vector": "array.array",
"ext::pgsparse::vector": "array.array",
}

TYPE_IMPORTS = {
Expand All @@ -79,19 +80,22 @@
"cal::local_time": "datetime",
"cal::local_datetime": "datetime",
"ext::pgvector::vector": "array",
"ext::pgsparse::vector": "array",
}

INPUT_TYPE_MAPPING = TYPE_MAPPING.copy()
INPUT_TYPE_MAPPING.update(
{
"ext::pgvector::vector": "typing.Sequence[float]",
"ext::pgsparse::vector": "typing.Sequence[float]",
}
)

INPUT_TYPE_IMPORTS = TYPE_IMPORTS.copy()
INPUT_TYPE_IMPORTS.update(
{
"ext::pgvector::vector": "typing",
"ext::pgsparse::vector": "typing",
}
)

Expand Down
137 changes: 75 additions & 62 deletions tests/codegen/test-project2/generated_async_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import typing
import uuid


Input = typing.Sequence[float]
Input0 = typing.Sequence[float]
Input1 = typing.Sequence[float]
MyScalar = int


Expand Down Expand Up @@ -118,6 +119,8 @@ class MyQueryResult:
bb: MyEnum | None
bc: array.array
bd: array.array | None
be: array.array
bf: array.array | None


@dataclasses.dataclass
Expand Down Expand Up @@ -145,13 +148,17 @@ class SelectObjectResultParamsItem:
async def custom_vector_input(
executor: edgedb.AsyncIOExecutor,
*,
input: Input | None = None,
input0: Input | None = None,
input1: Input | None = None,
) -> int | None:
return await executor.query_single(
"""\
select 42 filter exists <optional v3>$input;\
select 42 filter
exists <optional v3>$input0
or exists <optional sv3>$input1;\
""",
input=input,
input0=input0,
input1=input1,
)


Expand Down Expand Up @@ -237,69 +244,73 @@ async def my_query(
ax: edgedb.Range[datetime.date] | None = None,
bc: typing.Sequence[float],
bd: typing.Sequence[float] | None = None,
be: typing.Sequence[float],
bf: typing.Sequence[float] | None = None,
) -> MyQueryResult:
return await executor.query_single(
"""\
create scalar type MyScalar extending int64;
create scalar type MyEnum extending enum<'This', 'That', '1', 'f. b', 'f-b'>;

select {
a := <uuid>$a,
b := <optional uuid>$b,
c := <str>$c,
d := <optional str>$d,
e := <bytes>$e,
f := <optional bytes>$f,
g := <int16>$g,
h := <optional int16>$h,
i := <int32>$i,
j := <optional int32>$j,
k := <int64>$k,
l := <optional int64>$l,
m := <float32>$m,
n := <optional float32>$n,
o := <float64>$o,
p := <optional float64>$p,
q := <bool>$q,
r := <optional bool>$r,
s := <datetime>$s,
t := <optional datetime>$t,
u := <cal::local_datetime>$u,
v := <optional cal::local_datetime>$v,
w := <cal::local_date>$w,
x := <optional cal::local_date>$x,
y := <cal::local_time>$y,
z := <optional cal::local_time>$z,
aa := <duration>$aa,
ab := <optional duration>$ab,
ac := <bigint>$ac,
ad := <optional bigint>$ad,
ae := <cal::relative_duration>$ae,
af := <optional cal::relative_duration>$af,
ag := <cal::date_duration>$ag,
ah := <optional cal::date_duration>$ah,
ai := <cfg::memory>$ai,
aj := <optional cfg::memory>$aj,
ak := <range<int32>>$ak,
al := <optional range<int32>>$al,
am := <range<int64>>$am,
an := <optional range<int64>>$an,
ao := <range<float32>>$ao,
ap := <optional range<float32>>$ap,
aq := <range<float64>>$aq,
ar := <optional range<float64>>$ar,
as_ := <range<datetime>>$as_,
at := <optional range<datetime>>$at,
au := <range<cal::local_datetime>>$au,
av := <optional range<cal::local_datetime>>$av,
aw := <range<cal::local_date>>$aw,
ax := <optional range<cal::local_date>>$ax,
ay := <MyScalar>1,
az := <optional MyScalar>{},
ba := MyEnum.This,
bb := <optional MyEnum>{},
bc := <ext::pgvector::vector>$bc,
bd := <optional ext::pgvector::vector>$bd,
a := <uuid>$a,
b := <optional uuid>$b,
c := <str>$c,
d := <optional str>$d,
e := <bytes>$e,
f := <optional bytes>$f,
g := <int16>$g,
h := <optional int16>$h,
i := <int32>$i,
j := <optional int32>$j,
k := <int64>$k,
l := <optional int64>$l,
m := <float32>$m,
n := <optional float32>$n,
o := <float64>$o,
p := <optional float64>$p,
q := <bool>$q,
r := <optional bool>$r,
s := <datetime>$s,
t := <optional datetime>$t,
u := <cal::local_datetime>$u,
v := <optional cal::local_datetime>$v,
w := <cal::local_date>$w,
x := <optional cal::local_date>$x,
y := <cal::local_time>$y,
z := <optional cal::local_time>$z,
aa := <duration>$aa,
ab := <optional duration>$ab,
ac := <bigint>$ac,
ad := <optional bigint>$ad,
ae := <cal::relative_duration>$ae,
af := <optional cal::relative_duration>$af,
ag := <cal::date_duration>$ag,
ah := <optional cal::date_duration>$ah,
ai := <cfg::memory>$ai,
aj := <optional cfg::memory>$aj,
ak := <range<int32>>$ak,
al := <optional range<int32>>$al,
am := <range<int64>>$am,
an := <optional range<int64>>$an,
ao := <range<float32>>$ao,
ap := <optional range<float32>>$ap,
aq := <range<float64>>$aq,
ar := <optional range<float64>>$ar,
as_ := <range<datetime>>$as_,
at := <optional range<datetime>>$at,
au := <range<cal::local_datetime>>$au,
av := <optional range<cal::local_datetime>>$av,
aw := <range<cal::local_date>>$aw,
ax := <optional range<cal::local_date>>$ax,
ay := <MyScalar>1,
az := <optional MyScalar>{},
ba := MyEnum.This,
bb := <optional MyEnum>{},
bc := <ext::pgvector::vector>$bc,
bd := <optional ext::pgvector::vector>$bd,
be := <ext::pgsparse::vector>$be,
bf := <optional ext::pgsparse::vector>$bf,
}\
""",
a=a,
Expand Down Expand Up @@ -354,6 +365,8 @@ async def my_query(
ax=ax,
bc=bc,
bd=bd,
be=be,
bf=bf,
)


Expand All @@ -379,8 +392,8 @@ async def select_args(
return await executor.query_single(
"""\
select {
Str := <str>$arg_str,
DateTime := <datetime>$arg_datetime,
Str := <str>$arg_str,
DateTime := <datetime>$arg_datetime,
}\
""",
arg_str=arg_str,
Expand Down
Loading

0 comments on commit e51a1b1

Please sign in to comment.