Skip to content

Commit

Permalink
Add support for Network Address Types fixes: #50
Browse files Browse the repository at this point in the history
  • Loading branch information
andre1sk committed Jun 14, 2019
1 parent fd3200f commit 3d46da6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ function decodeText(value: Uint8Array, typeOid: number): any {
case Oid.text:
case Oid.time:
case Oid.timetz:
case Oid.inet:
case Oid.cidr:
case Oid.macaddr:
return strValue;
case Oid.bool:
return strValue[0] === "t";
Expand Down
1 change: 1 addition & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import "./tests/connection_params.ts";
import "./tests/client.ts";
import "./tests/pool.ts";
import "./tests/utils.ts";
import "./tests/decode.ts";

runTests();
48 changes: 48 additions & 0 deletions tests/decode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, assertEquals } from "../deps.ts";
import { Column, Format } from "../connection.ts";
import { Oid } from "../oid.ts";
import { decode } from "../decode.ts";

const encoder = new TextEncoder();

test(function decodeInet() {
const column = new Column(
"inet_col", // name
16410, // tableOid
1, // index
Oid.inet, // dataTypeOid
-1, // columnLength
-1, // typeModifier
Format.TEXT // format
);
const value = encoder.encode("127.0.0.1");
assertEquals(decode(value, column), "127.0.0.1");
});

test(function decodeMacaddr() {
const column = new Column(
"mac_col", // name
16410, // tableOid
2, // index
Oid.macaddr, // dataTypeOid
-1, // columnLength
-1, // typeModifier
Format.TEXT // format
);
const value = encoder.encode("08:00:2b:01:02:03");
assertEquals(decode(value, column), "08:00:2b:01:02:03");
});

test(function decodeCidr() {
const column = new Column(
"cidr_col", // name
16410, // tableOid
2, // index
Oid.cidr, // dataTypeOid
-1, // columnLength
-1, // typeModifier
Format.TEXT // format
);
const value = encoder.encode("192.168.100.128/25");
assertEquals(decode(value, column), "192.168.100.128/25");
});

0 comments on commit 3d46da6

Please sign in to comment.