url type added

+ support for `Url` columns
This commit is contained in:
michal-kapala
2023-06-28 02:16:09 +02:00
parent 63bf053c36
commit 3c78bb2a1b
7 changed files with 59 additions and 7 deletions

View File

@ -17,7 +17,7 @@ import {
PocketbaseType,
} from "../types/pocketbase.ts";
import { createSchemaField, generateRowSchema } from "./pocketbase.ts";
import { isBool, isDate, isEmail, isJson, isNumber } from "./regex.ts";
import { isBool, isDate, isEmail, isJson, isNumber, isUrl } from "./regex.ts";
/**
* Reads raw data from a CSV file.
@ -122,6 +122,10 @@ export function addSchemaField(data: RawCsvRow[], prop: string): SchemaField {
return createSchemaField(targetProp, "date");
}
if (isUrl(data, prop)) {
return createSchemaField(targetProp, "url");
}
// Plain text is the default type
return createSchemaField(targetProp, "text");
}
@ -206,6 +210,8 @@ function parseValue(value: string, type: PocketbaseType): any {
return value !== "" ? value : null;
case POCKETBASE_TYPE.DATETIME:
return value !== "" ? value : null;
case POCKETBASE_TYPE.URL:
return value !== "" ? value : null;
default:
console.error(
`%cPbTypeError: value parser for type '${type}' is not yet implemented.`,