mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 16:03:21 +00:00
fix: support all pg types from db studio (#3613)
* fix: support all pg types from db studio * chore: parser pkg frontend update
This commit is contained in:
@@ -292,22 +292,29 @@ pub fn parse_pg_typ(typ: &str) -> Typ {
|
||||
Typ::List(Box::new(base_typ))
|
||||
} else {
|
||||
match typ {
|
||||
"varchar" => Typ::Str(None),
|
||||
"varchar" | "character varying" => Typ::Str(None),
|
||||
"text" => Typ::Str(None),
|
||||
"int" => Typ::Int,
|
||||
"int" | "integer" | "int4" => Typ::Int,
|
||||
"bigint" => Typ::Int,
|
||||
"bool" => Typ::Bool,
|
||||
"char" => Typ::Str(None),
|
||||
"smallint" => Typ::Int,
|
||||
"smallserial" => Typ::Int,
|
||||
"serial" => Typ::Int,
|
||||
"bigserial" => Typ::Int,
|
||||
"real" => Typ::Float,
|
||||
"double precision" => Typ::Float,
|
||||
"numeric" => Typ::Float,
|
||||
"decimal" => Typ::Float,
|
||||
"bool" | "boolean" => Typ::Bool,
|
||||
"char" | "character" => Typ::Str(None),
|
||||
"smallint" | "int2" => Typ::Int,
|
||||
"smallserial" | "serial2" => Typ::Int,
|
||||
"serial" | "serial4" => Typ::Int,
|
||||
"bigserial" | "serial8" => Typ::Int,
|
||||
"real" | "float4" => Typ::Float,
|
||||
"double" | "double precision" | "float8" => Typ::Float,
|
||||
"numeric" | "decimal" => Typ::Float,
|
||||
"oid" => Typ::Int,
|
||||
"date" | "time" | "timestamp" | "timestamptz" => Typ::Datetime,
|
||||
"date"
|
||||
| "time"
|
||||
| "timetz"
|
||||
| "time with time zone"
|
||||
| "time without time zone"
|
||||
| "timestamp"
|
||||
| "timestamptz"
|
||||
| "timestamp with time zone"
|
||||
| "timestamp without time zone" => Typ::Datetime,
|
||||
_ => Typ::Str(None),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"collaborators": [
|
||||
"Ruben Fiszel <ruben@windmill.dev>"
|
||||
],
|
||||
"version": "1.286.2",
|
||||
"version": "1.317.1",
|
||||
"files": [
|
||||
"windmill_parser_wasm_bg.wasm",
|
||||
"windmill_parser_wasm.js",
|
||||
|
||||
@@ -97,15 +97,6 @@ function getInt32Memory0() {
|
||||
return cachedInt32Memory0;
|
||||
}
|
||||
|
||||
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
||||
|
||||
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
@@ -115,6 +106,15 @@ function addHeapObject(obj) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
||||
|
||||
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
let cachedFloat64Memory0 = null;
|
||||
|
||||
function getFloat64Memory0() {
|
||||
@@ -561,7 +561,7 @@ async function __wbg_load(module, imports) {
|
||||
function __wbg_get_imports() {
|
||||
const imports = {};
|
||||
imports.wbg = {};
|
||||
imports.wbg.__wbg_eval_89aaea39f7e976e8 = function(arg0, arg1) {
|
||||
imports.wbg.__wbg_eval_2b43744c6689f0c5 = function(arg0, arg1) {
|
||||
const ret = eval(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
@@ -576,10 +576,6 @@ function __wbg_get_imports() {
|
||||
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
||||
};
|
||||
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
||||
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
||||
const v = getObject(arg0);
|
||||
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
||||
@@ -601,6 +597,10 @@ function __wbg_get_imports() {
|
||||
const ret = BigInt.asUintN(64, arg0);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
||||
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof(obj) === 'number' ? obj : undefined;
|
||||
|
||||
Binary file not shown.
Generated
+8
-8
@@ -53,8 +53,8 @@
|
||||
"vscode-languageclient": "~9.0.1",
|
||||
"vscode-uri": "~3.0.8",
|
||||
"vscode-ws-jsonrpc": "~3.1.0",
|
||||
"windmill-parser-wasm": "^1.286.2",
|
||||
"windmill-sql-datatype-parser-wasm": "1.305.0",
|
||||
"windmill-parser-wasm": "^1.317.1",
|
||||
"windmill-sql-datatype-parser-wasm": "^1.317.1",
|
||||
"y-monaco": "^0.1.4",
|
||||
"y-websocket": "^1.5.0",
|
||||
"yaml": "^2.3.4",
|
||||
@@ -10310,14 +10310,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/windmill-parser-wasm": {
|
||||
"version": "1.286.2",
|
||||
"resolved": "https://registry.npmjs.org/windmill-parser-wasm/-/windmill-parser-wasm-1.286.2.tgz",
|
||||
"integrity": "sha512-xwmIRy/QJoT/p5MpZw5O1Ed4T25gOjHvR4VpkJTxeMhhzRzhXA52gBRABRGL1lZImo74kWTHdMVQ/UdKB7yO0g=="
|
||||
"version": "1.317.1",
|
||||
"resolved": "https://registry.npmjs.org/windmill-parser-wasm/-/windmill-parser-wasm-1.317.1.tgz",
|
||||
"integrity": "sha512-QFXoEenDAY5u0xrUWXuX2a2DcUBI0fEADP4uUttPZ5LgoQ6xKuIeKRaFKE/D7vsjhB2a2tYPpwS6DaaBaA/Dew=="
|
||||
},
|
||||
"node_modules/windmill-sql-datatype-parser-wasm": {
|
||||
"version": "1.305.0",
|
||||
"resolved": "https://registry.npmjs.org/windmill-sql-datatype-parser-wasm/-/windmill-sql-datatype-parser-wasm-1.305.0.tgz",
|
||||
"integrity": "sha512-tn0yVn61g6EQp4t7zVnH6ZeL1CbjSSPinpMB8PwbxCTcv+dj5ibWRzYmNu+bqzcLjwdMTUA6VRHsbYJ3Ne4HpQ=="
|
||||
"version": "1.317.1",
|
||||
"resolved": "https://registry.npmjs.org/windmill-sql-datatype-parser-wasm/-/windmill-sql-datatype-parser-wasm-1.317.1.tgz",
|
||||
"integrity": "sha512-1r6IipZNmpYV6OX+WczxaA7slcA5sLt5f+QsuTStQtUFoxyLDl0otUphWIaSvbKg27ATG4KTtmLQZ2ADdgAzSA=="
|
||||
},
|
||||
"node_modules/wordwrap": {
|
||||
"version": "1.0.0",
|
||||
|
||||
@@ -133,8 +133,8 @@
|
||||
"vscode-languageclient": "~9.0.1",
|
||||
"vscode-uri": "~3.0.8",
|
||||
"vscode-ws-jsonrpc": "~3.1.0",
|
||||
"windmill-parser-wasm": "^1.286.2",
|
||||
"windmill-sql-datatype-parser-wasm": "1.305.0",
|
||||
"windmill-parser-wasm": "^1.317.1",
|
||||
"windmill-sql-datatype-parser-wasm": "^1.317.1",
|
||||
"y-monaco": "^0.1.4",
|
||||
"y-websocket": "^1.5.0",
|
||||
"yaml": "^2.3.4",
|
||||
@@ -418,4 +418,4 @@
|
||||
"optionalDependencies": {
|
||||
"fsevents": "^2.3.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Schema, SchemaProperty } from '$lib/common'
|
||||
import LightweightSchemaForm from '$lib/components/LightweightSchemaForm.svelte'
|
||||
import {
|
||||
ColumnIdentity,
|
||||
getFieldType,
|
||||
type ColumnMetadata,
|
||||
type DbType,
|
||||
type ColumnDef
|
||||
} from './utils'
|
||||
import { ColumnIdentity, type ColumnMetadata, type DbType, type ColumnDef } from './utils'
|
||||
|
||||
import init, {
|
||||
parse_sql,
|
||||
@@ -34,7 +28,6 @@
|
||||
name: string
|
||||
isPrimaryKey: boolean
|
||||
defaultValue: string | undefined
|
||||
fieldType: 'text' | 'number' | 'checkbox' | 'date'
|
||||
identity: ColumnIdentity
|
||||
nullable: 'YES' | 'NO'
|
||||
}
|
||||
@@ -50,14 +43,12 @@
|
||||
const name = column.field
|
||||
const isPrimaryKey = column.isprimarykey
|
||||
const defaultValue = column.defaultValueNull ? null : column.defaultUserValue
|
||||
const fieldType = getFieldType(type, dbType)
|
||||
|
||||
return {
|
||||
type,
|
||||
name,
|
||||
isPrimaryKey,
|
||||
defaultValue,
|
||||
fieldType,
|
||||
identity: column.isidentity,
|
||||
nullable: column.isnullable
|
||||
}
|
||||
@@ -114,15 +105,10 @@
|
||||
|
||||
const parsedArg = columnDefs.find((arg) => arg.field === field.name)
|
||||
if (parsedArg) {
|
||||
let typ: any = rawTypeToSchemaType(parseSQLArgs(parsedArg.datatype, dbType))
|
||||
argSigToJsonSchemaType(typ, schemaProperty)
|
||||
console.log(
|
||||
'schemaProperty',
|
||||
schemaProperty,
|
||||
field.name,
|
||||
typ,
|
||||
parseSQLArgs(parsedArg.datatype, dbType)
|
||||
let typ: any = rawTypeToSchemaType(
|
||||
parseSQLArgs(parsedArg.datatype.split('(')[0].trim(), dbType)
|
||||
)
|
||||
argSigToJsonSchemaType(typ, schemaProperty)
|
||||
}
|
||||
|
||||
if (field.defaultValue) {
|
||||
|
||||
@@ -2,26 +2,12 @@ import type { AppInput } from '$lib/components/apps/inputType'
|
||||
import { buildParameters, ColumnIdentity, type DbType } from '../utils'
|
||||
import { getLanguageByResourceType, type ColumnDef } from '../utils'
|
||||
|
||||
function mapDataTypeToDbType(dataType: string): string {
|
||||
if (dataType === 'integer') {
|
||||
return 'int'
|
||||
}
|
||||
|
||||
if (dataType === 'boolean') {
|
||||
return 'bool'
|
||||
}
|
||||
|
||||
return dataType
|
||||
}
|
||||
|
||||
function formatInsertValues(columns: ColumnDef[], dbType: DbType, startIndex: number = 1): string {
|
||||
switch (dbType) {
|
||||
case 'mysql':
|
||||
return columns.map((c) => `:${c.field}`).join(', ')
|
||||
case 'postgresql':
|
||||
return columns
|
||||
.map((c, i) => `$${startIndex + i}::${mapDataTypeToDbType(c.datatype)}`)
|
||||
.join(', ')
|
||||
return columns.map((c, i) => `$${startIndex + i}::${c.datatype}`).join(', ')
|
||||
case 'ms_sql_server':
|
||||
return columns.map((c, i) => `@p${startIndex + i}`).join(', ')
|
||||
case 'snowflake':
|
||||
|
||||
@@ -529,96 +529,6 @@ export function formatGraphqlSchema(schema: IntrospectionQuery): string {
|
||||
return printSchema(buildClientSchema(schema))
|
||||
}
|
||||
|
||||
export function getFieldType(type: string, databaseType: DbType) {
|
||||
switch (databaseType) {
|
||||
case 'postgresql': {
|
||||
const baseType = type.split('(')[0]
|
||||
const validTextTypes = ['character varying', 'text']
|
||||
const validNumberTypes = ['integer', 'bigint', 'numeric', 'double precision']
|
||||
const validDateTypes = ['date', 'timestamp without time zone', 'timestamp with time zone']
|
||||
|
||||
return validTextTypes.includes(baseType)
|
||||
? 'text'
|
||||
: validNumberTypes.includes(baseType)
|
||||
? 'number'
|
||||
: baseType === 'boolean'
|
||||
? 'checkbox'
|
||||
: validDateTypes.includes(baseType)
|
||||
? 'date'
|
||||
: 'text'
|
||||
}
|
||||
case 'mysql': {
|
||||
const baseType = type.split('(')[0].toLowerCase() // Ensure case-insensitive comparison
|
||||
const validTextTypes = ['varchar', 'text', 'char', 'mediumtext', 'longtext', 'tinytext']
|
||||
const validNumberTypes = ['int', 'bigint', 'decimal', 'numeric', 'float', 'double']
|
||||
const validDateTypes = ['date', 'datetime', 'timestamp', 'time', 'year']
|
||||
|
||||
return validTextTypes.includes(baseType)
|
||||
? 'text'
|
||||
: validNumberTypes.includes(baseType)
|
||||
? 'number'
|
||||
: baseType === 'boolean'
|
||||
? 'checkbox'
|
||||
: validDateTypes.includes(baseType)
|
||||
? 'date'
|
||||
: 'text'
|
||||
}
|
||||
case 'ms_sql_server': {
|
||||
const baseType = type.split('(')[0].toLowerCase() // Ensure case-insensitive comparison
|
||||
const validTextTypes = ['varchar', 'text', 'char', 'nchar', 'nvarchar', 'ntext']
|
||||
const validNumberTypes = [
|
||||
'int',
|
||||
'bigint',
|
||||
'decimal',
|
||||
'numeric',
|
||||
'float',
|
||||
'real',
|
||||
'smallint',
|
||||
'tinyint'
|
||||
]
|
||||
const validDateTypes = [
|
||||
'date',
|
||||
'datetime',
|
||||
'datetime2',
|
||||
'smalldatetime',
|
||||
'datetimeoffset',
|
||||
'time'
|
||||
]
|
||||
|
||||
return validTextTypes.includes(baseType)
|
||||
? 'text'
|
||||
: validNumberTypes.includes(baseType)
|
||||
? 'number'
|
||||
: baseType === 'bit'
|
||||
? 'checkbox'
|
||||
: validDateTypes.includes(baseType)
|
||||
? 'date'
|
||||
: 'text'
|
||||
}
|
||||
|
||||
case 'snowflake': {
|
||||
const baseType = type.split('(')[0].toLowerCase() // Ensure case-insensitive comparison
|
||||
const validTextTypes = ['varchar', 'text', 'char']
|
||||
const validNumberTypes = ['int', 'number', 'decimal', 'float', 'double']
|
||||
const validDateTypes = ['date', 'timestamp', 'time']
|
||||
|
||||
return validTextTypes.includes(baseType)
|
||||
? 'text'
|
||||
: validNumberTypes.includes(baseType)
|
||||
? 'number'
|
||||
: baseType === 'boolean'
|
||||
? 'checkbox'
|
||||
: validDateTypes.includes(baseType)
|
||||
? 'date'
|
||||
: 'text'
|
||||
}
|
||||
|
||||
default: {
|
||||
return 'text'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type DbType = 'mysql' | 'ms_sql_server' | 'postgresql' | 'snowflake' | 'bigquery'
|
||||
|
||||
export function buildVisibleFieldList(columnDefs: ColumnDef[], dbType: DbType) {
|
||||
|
||||
Reference in New Issue
Block a user