@postgresql-typed/cache
Advanced tools
Comparing version
@@ -12,3 +12,3 @@ import { definePgTExtension } from "@postgresql-typed/util"; | ||
}, | ||
setup(resolvedOptions, pgt) { | ||
setup(resolvedOptions, manager) { | ||
const { uri, namespace, ttl, types } = resolvedOptions, keyv = new Keyv({ | ||
@@ -21,3 +21,3 @@ uri, | ||
}); | ||
pgt.hook("client:pre-query", async (data) => { | ||
manager.hook("pgt:pre-query", async (data) => { | ||
//* If another hook has already set the output, don't do anything | ||
@@ -27,10 +27,10 @@ /* c8 ignore next 1 */ | ||
return; | ||
if (!types.includes(data.input.query.trim().split(" ")[0].toLowerCase())) | ||
if (!types.includes(data.input.query.text.trim().split(" ")[0].toLowerCase())) | ||
return; | ||
const hashed = hash(data.input), foundCache = await keyv.get(hashed); | ||
const hashed = hash(data.input, {}), foundCache = await keyv.get(hashed); | ||
if (foundCache !== undefined) | ||
data.output = foundCache; | ||
}); | ||
pgt.hook("client:post-query", async (data) => { | ||
if (!types.includes(data.input.query.trim().split(" ")[0].toLowerCase())) | ||
manager.hook("pgt:post-query", async (data) => { | ||
if (!types.includes(data.input.query.text.trim().split(" ")[0].toLowerCase())) | ||
return; | ||
@@ -37,0 +37,0 @@ const hashed = hash(data.input, {}), isCached = await keyv.has(hashed); |
@@ -1,2 +0,2 @@ | ||
import { Bit, BitVarying, Boolean, Box, Character, CharacterVarying, Circle, Date, DateMultiRange, DateRange, Float4, Float8, Int2, Int4, Int4MultiRange, Int4Range, Int8, Int8MultiRange, Int8Range, Interval, Line, LineSegment, Money, Name, OID, Path, Point, Polygon, Text, Time, Timestamp, TimestampMultiRange, TimestampRange, TimestampTZ, TimestampTZMultiRange, TimestampTZRange, TimeTZ, UUID, } from "@postgresql-typed/parsers"; | ||
import { Bit, BitVarying, Boolean, Box, Character, CharacterVarying, Circle, Date, DateMultiRange, DateRange, Float4, Float8, Int2, Int4, Int4MultiRange, Int4Range, Int8, Int8MultiRange, Int8Range, Interval, JSON, Line, LineSegment, Money, Name, OID, Path, Point, Polygon, Text, Time, Timestamp, TimestampMultiRange, TimestampRange, TimestampTZ, TimestampTZMultiRange, TimestampTZRange, TimeTZ, UUID, } from "@postgresql-typed/parsers"; | ||
export function deserializer(object) { | ||
@@ -27,3 +27,3 @@ if (typeof object !== "object" || object === null) | ||
return Date.from(rest); | ||
/* c8 ignore next 3 */ | ||
/* c8 ignore next 5 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -42,3 +42,3 @@ case "dateMultiRange": | ||
return Int4.from(rest); | ||
/* c8 ignore next 3 */ | ||
/* c8 ignore next 5 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -51,3 +51,3 @@ case "int4MultiRange": | ||
return Int8.from(rest); | ||
/* c8 ignore next 3 */ | ||
/* c8 ignore next 5 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -76,2 +76,4 @@ case "int8MultiRange": | ||
return Polygon.from(rest); | ||
case "json": | ||
return JSON.from(rest); | ||
case "text": | ||
@@ -83,3 +85,3 @@ return Text.from(rest); | ||
return Timestamp.from(rest); | ||
/* c8 ignore next 3 */ | ||
/* c8 ignore next 5 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -92,3 +94,3 @@ case "timestampMultiRange": | ||
return TimestampTZ.from(rest); | ||
/* c8 ignore next 3 */ | ||
/* c8 ignore next 5 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -95,0 +97,0 @@ case "timestampTZMultiRange": |
@@ -1,2 +0,2 @@ | ||
import { Bit, BitVarying, Boolean, Box, Character, CharacterVarying, Circle, Date, DateMultiRange, DateRange, Float4, Float8, Int2, Int4, Int4MultiRange, Int4Range, Int8, Int8MultiRange, Int8Range, Interval, Line, LineSegment, Money, Name, OID, Path, Point, Polygon, Text, Time, Timestamp, TimestampMultiRange, TimestampRange, TimestampTZ, TimestampTZMultiRange, TimestampTZRange, TimeTZ, UUID, } from "@postgresql-typed/parsers"; | ||
import { Bit, BitVarying, Boolean, Box, Character, CharacterVarying, Circle, Date, DateMultiRange, DateRange, Float4, Float8, Int2, Int4, Int4MultiRange, Int4Range, Int8, Int8MultiRange, Int8Range, Interval, JSON, Line, LineSegment, Money, Name, OID, Path, Point, Polygon, Text, Time, Timestamp, TimestampMultiRange, TimestampRange, TimestampTZ, TimestampTZMultiRange, TimestampTZRange, TimeTZ, UUID, } from "@postgresql-typed/parsers"; | ||
export function serializer(object) { | ||
@@ -23,3 +23,3 @@ if (typeof object !== "object" || object === null) | ||
return toJSON("date", object); | ||
/* c8 ignore next 2 */ | ||
/* c8 ignore next 3 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -38,3 +38,3 @@ if (DateMultiRange.isMultiRange(object)) | ||
return toJSON("int4", object); | ||
/* c8 ignore next 2 */ | ||
/* c8 ignore next 3 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -47,3 +47,3 @@ if (Int4MultiRange.isMultiRange(object)) | ||
return toJSON("int8", object); | ||
/* c8 ignore next 2 */ | ||
/* c8 ignore next 3 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -72,2 +72,4 @@ if (Int8MultiRange.isMultiRange(object)) | ||
return toJSON("polygon", object); | ||
if (JSON.isJSON(object)) | ||
return toJSON("json", object); | ||
if (Text.isText(object)) | ||
@@ -79,3 +81,3 @@ return toJSON("text", object); | ||
return toJSON("timestamp", object); | ||
/* c8 ignore next 2 */ | ||
/* c8 ignore next 3 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -88,3 +90,3 @@ if (TimestampMultiRange.isMultiRange(object)) | ||
return toJSON("timestampTZ", object); | ||
/* c8 ignore next 2 */ | ||
/* c8 ignore next 3 */ | ||
// Not all postgres versions support this type, it is tested in higher versions. | ||
@@ -91,0 +93,0 @@ if (TimestampTZMultiRange.isMultiRange(object)) |
{ | ||
"name": "@postgresql-typed/cache", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "A PostgreSQL-Typed extension to cache queries using Keyv", | ||
@@ -46,4 +46,4 @@ "type": "module", | ||
"source-map-support": "^0.5.21", | ||
"@postgresql-typed/parsers": "0.6.1", | ||
"@postgresql-typed/util": "0.4.0" | ||
"@postgresql-typed/parsers": "0.7.0", | ||
"@postgresql-typed/util": "0.5.0" | ||
}, | ||
@@ -54,9 +54,9 @@ "devDependencies": { | ||
"typescript": "^4.9.5", | ||
"@postgresql-typed/cli": "0.3.2", | ||
"@postgresql-typed/postgres": "0.3.6" | ||
"@postgresql-typed/cli": "0.4.0", | ||
"@postgresql-typed/core": "0.5.0" | ||
}, | ||
"packageManager": "pnpm@7.17.0", | ||
"packageManager": "pnpm@8.6.0", | ||
"engines": { | ||
"node": ">=16", | ||
"pnpm": ">=7.17.0" | ||
"pnpm": ">=8.6.0" | ||
}, | ||
@@ -63,0 +63,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46450
0.75%319
1.27%+ Added
+ Added
- Removed
- Removed
Updated