Compare commits
3 Commits
a88da00dec
...
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
3793e14f50
|
|||
|
b194397645
|
|||
|
858b7a95f3
|
@@ -14,9 +14,9 @@ The glue for TypeScript to PostgreSQL.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import pglue from "https://git.lua.re/luaneko/pglue/raw/tag/0.1.1/mod.ts";
|
import pglue from "https://git.lua.re/luaneko/pglue/raw/tag/v0.1.3/mod.ts";
|
||||||
// ...or from github:
|
// ...or from github:
|
||||||
import pglue from "https://raw.githubusercontent.com/luaneko/pglue/refs/tags/0.1.1/mod.ts";
|
import pglue from "https://raw.githubusercontent.com/luaneko/pglue/refs/tags/v0.1.3/mod.ts";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@luaneko/pglue",
|
"name": "@luaneko/pglue",
|
||||||
"version": "0.1.1",
|
"version": "0.1.3",
|
||||||
"exports": "./mod.ts"
|
"exports": "./mod.ts"
|
||||||
}
|
}
|
||||||
|
|||||||
12
deno.lock
generated
12
deno.lock
generated
@@ -460,11 +460,11 @@
|
|||||||
"https://deno.land/x/postgresjs@v3.4.5/src/result.js": "001ff5e0c8d634674f483d07fbcd620a797e3101f842d6c20ca3ace936260465",
|
"https://deno.land/x/postgresjs@v3.4.5/src/result.js": "001ff5e0c8d634674f483d07fbcd620a797e3101f842d6c20ca3ace936260465",
|
||||||
"https://deno.land/x/postgresjs@v3.4.5/src/subscribe.js": "9e4d0c3e573a6048e77ee2f15abbd5bcd17da9ca85a78c914553472c6d6c169b",
|
"https://deno.land/x/postgresjs@v3.4.5/src/subscribe.js": "9e4d0c3e573a6048e77ee2f15abbd5bcd17da9ca85a78c914553472c6d6c169b",
|
||||||
"https://deno.land/x/postgresjs@v3.4.5/src/types.js": "471f4a6c35412aa202a7c177c0a7e5a7c3bd225f01bbde67c947894c1b8bf6ed",
|
"https://deno.land/x/postgresjs@v3.4.5/src/types.js": "471f4a6c35412aa202a7c177c0a7e5a7c3bd225f01bbde67c947894c1b8bf6ed",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e",
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/bytes.ts": "5ffb12787dc3f9ef9680b6e2e4f5f9903783aa4c33b69e725b5df1d1c116bfe6",
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/bytes.ts": "5ffb12787dc3f9ef9680b6e2e4f5f9903783aa4c33b69e725b5df1d1c116bfe6",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/events.ts": "28d395b8eea87f9bf7908a44b351d2d3c609ba7eab62bcecd0d43be8ee603438",
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/events.ts": "28d395b8eea87f9bf7908a44b351d2d3c609ba7eab62bcecd0d43be8ee603438",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff",
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/jit.ts": "c1db7820de95c48521b057c7cdf9aa41f7eaba77462407c29d3932e7da252d53",
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/jit.ts": "c1db7820de95c48521b057c7cdf9aa41f7eaba77462407c29d3932e7da252d53",
|
||||||
"https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/mod.ts": "95d8b15048a54cb82391825831f695b74e7c8b206317264a99c906ce25c63f13"
|
"https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/mod.ts": "95d8b15048a54cb82391825831f695b74e7c8b206317264a99c906ce25c63f13"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
lstd.ts
2
lstd.ts
@@ -1 +1 @@
|
|||||||
export * from "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/mod.ts";
|
export * from "https://git.lua.re/luaneko/lstd/raw/tag/v0.2.0/mod.ts";
|
||||||
|
|||||||
19
test.ts
19
test.ts
@@ -188,3 +188,22 @@ Deno.test(`transactions`, async () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(`streaming`, async () => {
|
||||||
|
await using pg = await connect();
|
||||||
|
await using _tx = await pg.begin();
|
||||||
|
|
||||||
|
await pg.query`create table my_table (field text not null)`;
|
||||||
|
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
await pg.query`insert into my_table (field) values (${i})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
for await (const chunk of pg.query`select * from my_table`.chunked(10)) {
|
||||||
|
expect(chunk.length).toBe(10);
|
||||||
|
for (const row of chunk) expect(row.field).toBe(`${i++}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(i).toBe(100);
|
||||||
|
});
|
||||||
|
|||||||
45
wire.ts
45
wire.ts
@@ -579,6 +579,11 @@ export class Wire extends TypedEmitter<WireEvents> implements Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const msg_PD = object({ P: Parse, D: Describe });
|
||||||
|
const msg_BE = object({ B: Bind, E: Execute });
|
||||||
|
const msg_BEc = object({ B: Bind, E: Execute, c: CopyDone });
|
||||||
|
const msg_BEcC = object({ B: Bind, E: Execute, c: CopyDone, C: Close });
|
||||||
|
|
||||||
function wire_impl(
|
function wire_impl(
|
||||||
wire: Wire,
|
wire: Wire,
|
||||||
socket: Deno.Conn,
|
socket: Deno.Conn,
|
||||||
@@ -904,10 +909,11 @@ function wire_impl(
|
|||||||
try {
|
try {
|
||||||
const { name, query } = this;
|
const { name, query } = this;
|
||||||
return await pipeline(
|
return await pipeline(
|
||||||
async () => {
|
() =>
|
||||||
await write(Parse, { statement: name, query, param_types: [] });
|
write(msg_PD, {
|
||||||
await write(Describe, { which: "S", name });
|
P: { statement: name, query, param_types: [] },
|
||||||
},
|
D: { which: "S", name },
|
||||||
|
}),
|
||||||
async () => {
|
async () => {
|
||||||
await read(ParseComplete);
|
await read(ParseComplete);
|
||||||
const param_desc = await read(ParameterDescription);
|
const param_desc = await read(ParameterDescription);
|
||||||
@@ -1078,16 +1084,23 @@ function wire_impl(
|
|||||||
try {
|
try {
|
||||||
const { rows, tag } = await pipeline(
|
const { rows, tag } = await pipeline(
|
||||||
async () => {
|
async () => {
|
||||||
await write(Bind, {
|
const B = {
|
||||||
portal,
|
portal,
|
||||||
statement: st.name,
|
statement: st.name,
|
||||||
param_formats: [],
|
param_formats: [],
|
||||||
param_values,
|
param_values,
|
||||||
column_formats: [],
|
column_formats: [],
|
||||||
});
|
};
|
||||||
await write(Execute, { portal, row_limit: 0 });
|
const E = { portal, row_limit: 0 };
|
||||||
await write_copy_in(stdin);
|
const C = { which: "P" as const, name: portal };
|
||||||
await write(Close, { which: "P" as const, name: portal });
|
|
||||||
|
if (stdin !== null) {
|
||||||
|
await write(msg_BE, { B, E });
|
||||||
|
await write_copy_in(stdin);
|
||||||
|
await write(Close, C);
|
||||||
|
} else {
|
||||||
|
return write(msg_BEcC, { B, E, c: {}, C });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
await read(BindComplete);
|
await read(BindComplete);
|
||||||
@@ -1131,15 +1144,21 @@ function wire_impl(
|
|||||||
try {
|
try {
|
||||||
let { done, rows, tag } = await pipeline(
|
let { done, rows, tag } = await pipeline(
|
||||||
async () => {
|
async () => {
|
||||||
await write(Bind, {
|
const B = {
|
||||||
portal,
|
portal,
|
||||||
statement: st.name,
|
statement: st.name,
|
||||||
param_formats: [],
|
param_formats: [],
|
||||||
param_values,
|
param_values,
|
||||||
column_formats: [],
|
column_formats: [],
|
||||||
});
|
};
|
||||||
await write(Execute, { portal, row_limit: chunk_size });
|
const E = { portal, row_limit: chunk_size };
|
||||||
await write_copy_in(stdin);
|
|
||||||
|
if (stdin !== null) {
|
||||||
|
await write(msg_BE, { B, E });
|
||||||
|
await write_copy_in(stdin);
|
||||||
|
} else {
|
||||||
|
return write(msg_BEc, { B, E, c: {} });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
await read(BindComplete);
|
await read(BindComplete);
|
||||||
|
|||||||
Reference in New Issue
Block a user