mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 02:36:00 +00:00
better type habndling, shell-tableReader for preserving table structure
This commit is contained in:
@@ -15,7 +15,7 @@ export function isTypeNumber(dataType) {
|
||||
}
|
||||
|
||||
export function isTypeString(dataType) {
|
||||
return dataType && /char/i.test(dataType);
|
||||
return dataType && /char|binary/i.test(dataType);
|
||||
}
|
||||
|
||||
export function isTypeLogical(dataType) {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './commonTypeParser';
|
||||
export * from './nameTools';
|
||||
|
||||
47
packages/tools/src/nameTools.ts
Normal file
47
packages/tools/src/nameTools.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { DatabaseInfo, DatabaseInfoObjects } from '@dbgate/types';
|
||||
|
||||
export function fullNameFromString(name) {
|
||||
const m = name.match(/\[([^\]]+)\]\.\[([^\]]+)\]/);
|
||||
if (m) {
|
||||
return {
|
||||
schemaName: m[1],
|
||||
pureName: m[2],
|
||||
};
|
||||
}
|
||||
return {
|
||||
schemaName: null,
|
||||
pureName: name,
|
||||
};
|
||||
}
|
||||
|
||||
export function fullNameToString({ schemaName, pureName }) {
|
||||
if (schemaName) {
|
||||
return `[${schemaName}].[${pureName}]`;
|
||||
}
|
||||
return pureName;
|
||||
}
|
||||
|
||||
export function quoteFullName(dialect, { schemaName, pureName }) {
|
||||
if (schemaName) return `${dialect.quoteIdentifier(schemaName)}.${dialect.quoteIdentifier(pureName)}`;
|
||||
return `${dialect.quoteIdentifier(pureName)}`;
|
||||
}
|
||||
|
||||
export function equalStringLike(s1, s2) {
|
||||
return (s1 || '').toLowerCase().trim() == (s2 || '').toLowerCase().trim();
|
||||
}
|
||||
|
||||
export function findObjectLike(
|
||||
{ pureName, schemaName },
|
||||
dbinfo: DatabaseInfo,
|
||||
objectTypeField: keyof DatabaseInfoObjects
|
||||
) {
|
||||
if (!dbinfo) return null;
|
||||
if (schemaName) {
|
||||
// @ts-ignore
|
||||
return dbinfo[objectTypeField].find(
|
||||
(x) => equalStringLike(x.pureName, pureName) && equalStringLike(x.schemaName, schemaName)
|
||||
);
|
||||
}
|
||||
// @ts-ignore
|
||||
return dbinfo[objectTypeField].find((x) => equalStringLike(x.pureName, pureName));
|
||||
}
|
||||
Reference in New Issue
Block a user