diff --git a/package.json b/package.json index 4d84585ad..6564a802f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "react-chessboard": "^4.6.0", "typescript": "^5.4.5", "veaury": "^2.4.0", - "vite": "^5.3.3", + "vite": "^5.3.3", "vitepress": "^1.2.3", "vue": "^3.3.7", "vue-markdown-render": "^2.2.1" diff --git a/packages/modeldb-pg/src/api.ts b/packages/modeldb-pg/src/api.ts index 12b39319c..355fdced1 100644 --- a/packages/modeldb-pg/src/api.ts +++ b/packages/modeldb-pg/src/api.ts @@ -33,6 +33,7 @@ import { const primitiveColumnTypes = { integer: "BIGINT", float: "DECIMAL", + number: "DOUBLE PRECISION", string: "TEXT", bytes: "BYTEA", boolean: "BOOLEAN", diff --git a/packages/modeldb-pg/src/encoding.ts b/packages/modeldb-pg/src/encoding.ts index 4790b0c93..3575f0d97 100644 --- a/packages/modeldb-pg/src/encoding.ts +++ b/packages/modeldb-pg/src/encoding.ts @@ -71,7 +71,7 @@ export function encodePrimitiveValue( } else { throw new TypeError(`${modelName}/${property.name} must be a safely representable integer`) } - } else if (property.type === "float") { + } else if (property.type === "number" || property.type === "float") { if (typeof value === "number") { return value } else { @@ -176,7 +176,7 @@ export function decodePrimitiveValue(modelName: string, property: PrimitivePrope console.error("expected integer, got", value) throw new Error(`internal error - invalid ${modelName}/${property.name} value (expected integer)`) } - } else if (property.type === "float") { + } else if (property.type === "number" || property.type === "float") { if (typeof value === "string") { return parseFloat(value) } else { diff --git a/packages/modeldb-sqlite/src/api.ts b/packages/modeldb-sqlite/src/api.ts index edaba7958..e1de7ab39 100644 --- a/packages/modeldb-sqlite/src/api.ts +++ b/packages/modeldb-sqlite/src/api.ts @@ -37,6 +37,7 @@ type Params = Record<`p${string}`, string | number | Buffer | null> const primitiveColumnTypes = { integer: "INTEGER", float: "FLOAT", + number: "NUMERIC", string: "TEXT", bytes: "BLOB", boolean: "INTEGER", diff --git a/packages/modeldb-sqlite/src/encoding.ts b/packages/modeldb-sqlite/src/encoding.ts index c1d3142b5..c0e256646 100644 --- a/packages/modeldb-sqlite/src/encoding.ts +++ b/packages/modeldb-sqlite/src/encoding.ts @@ -77,7 +77,7 @@ function encodePrimitiveValue( } else { throw new TypeError(`${modelName}/${property.name} must be a safely representable integer`) } - } else if (property.type === "float") { + } else if (property.type === "number" || property.type === "float") { if (typeof value === "number") { return value } else { @@ -175,7 +175,7 @@ export function decodePrimitiveValue(modelName: string, property: PrimitivePrope console.error("expected integer, got", value) throw new Error(`internal error - invalid ${modelName}/${property.name} value (expected integer)`) } - } else if (property.type === "float") { + } else if (property.type === "number" || property.type === "float") { if (typeof value === "number") { return value } else { diff --git a/packages/modeldb/src/config.ts b/packages/modeldb/src/config.ts index 50d00f063..29507a60c 100644 --- a/packages/modeldb/src/config.ts +++ b/packages/modeldb/src/config.ts @@ -66,7 +66,7 @@ export function parseConfig(init: ModelSchema): Config { return { relations, models } } -export const primitivePropertyPattern = /^(integer|float|string|bytes|boolean|json)(\??)$/ +export const primitivePropertyPattern = /^(integer|float|number|string|bytes|boolean|json)(\??)$/ export const referencePropertyPattern = /^@([a-z0-9.-]+)(\??)$/ export const relationPropertyPattern = /^@([a-z0-9.-]+)\[\]$/ diff --git a/packages/modeldb/src/query.ts b/packages/modeldb/src/query.ts index 8e2ac7590..72b3bed05 100644 --- a/packages/modeldb/src/query.ts +++ b/packages/modeldb/src/query.ts @@ -159,6 +159,7 @@ const booleanOrder: Order = { export const primitiveTypeOrders: Record = { integer: numberOrder, float: numberOrder, + number: numberOrder, string: stringOrder, bytes: byteOrder, boolean: booleanOrder, diff --git a/packages/modeldb/src/types.ts b/packages/modeldb/src/types.ts index afc9bea6e..eefaca79c 100644 --- a/packages/modeldb/src/types.ts +++ b/packages/modeldb/src/types.ts @@ -1,7 +1,7 @@ // These are "init types" for the `models` value used to initialize the database. export type PrimaryKeyType = "primary" -export type PrimitiveType = "integer" | "float" | "string" | "bytes" | "boolean" | "json" +export type PrimitiveType = "integer" | "float" | "number" | "string" | "bytes" | "boolean" | "json" export type OptionalPrimitiveType = `${PrimitiveType}?` export type ReferenceType = `@${string}` export type OptionalReferenceType = `@${string}?` diff --git a/packages/modeldb/src/utils.ts b/packages/modeldb/src/utils.ts index 548430ecc..2c6676b78 100644 --- a/packages/modeldb/src/utils.ts +++ b/packages/modeldb/src/utils.ts @@ -33,7 +33,7 @@ export function validatePropertyValue(modelName: string, property: Property, val } else if (!Number.isSafeInteger(value)) { throw new TypeError(`write to db.${modelName}.${property.name}: must be a valid Number.isSafeInteger()`) } - } else if (property.type === "float") { + } else if (property.type === "number" || property.type === "float") { if (typeof value !== "number") { throw new TypeError(`write to db.${modelName}.${property.name}: expected a number, received a ${typeof value}`) }