mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 01:06:01 +00:00
SYNC: Merge pull request #5 from dbgate/feature/firestore
This commit is contained in:
@@ -42,8 +42,7 @@ function areDifferentRowCounts(db1: DatabaseInfo, db2: DatabaseInfo) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export class DatabaseAnalyser {
|
||||
export class DatabaseAnalyser<TClient = any> {
|
||||
structure: DatabaseInfo;
|
||||
modifications: DatabaseModification[];
|
||||
singleObjectFilter: any;
|
||||
@@ -51,7 +50,7 @@ export class DatabaseAnalyser {
|
||||
dialect: SqlDialect;
|
||||
logger: Logger;
|
||||
|
||||
constructor(public dbhan: DatabaseHandle, public driver: EngineDriver, version) {
|
||||
constructor(public dbhan: DatabaseHandle<TClient>, public driver: EngineDriver, version) {
|
||||
this.dialect = (driver?.dialectByVersion && driver?.dialectByVersion(version)) || driver?.dialect;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export const stringFilterBehaviour: FilterBehaviour = {
|
||||
export const logicalFilterBehaviour: FilterBehaviour = {
|
||||
supportBooleanValues: true,
|
||||
supportNullTesting: true,
|
||||
supportBooleanOrNull: true,
|
||||
supportSqlCondition: true,
|
||||
};
|
||||
|
||||
@@ -36,7 +37,8 @@ export const datetimeFilterBehaviour: FilterBehaviour = {
|
||||
|
||||
export const mongoFilterBehaviour: FilterBehaviour = {
|
||||
supportEquals: true,
|
||||
supportArrayTesting: true,
|
||||
supportEmptyArrayTesting: true,
|
||||
supportNotEmptyArrayTesting: true,
|
||||
supportNumberLikeComparison: true,
|
||||
supportStringInclusion: true,
|
||||
supportBooleanValues: true,
|
||||
@@ -57,11 +59,38 @@ export const evalFilterBehaviour: FilterBehaviour = {
|
||||
allowStringToken: true,
|
||||
};
|
||||
|
||||
export const firestoreFilterBehaviours: FilterBehaviour = {
|
||||
supportEquals: true,
|
||||
supportEmpty: false,
|
||||
supportNumberLikeComparison: true,
|
||||
supportDatetimeComparison: false,
|
||||
supportNullTesting: true,
|
||||
supportBooleanValues: true,
|
||||
supportEmptyArrayTesting: true,
|
||||
|
||||
supportStringInclusion: false,
|
||||
supportDatetimeSymbols: false,
|
||||
supportExistsTesting: false,
|
||||
supportSqlCondition: false,
|
||||
|
||||
allowStringToken: true,
|
||||
allowNumberToken: true,
|
||||
allowHexString: true,
|
||||
allowNumberDualTesting: false,
|
||||
allowObjectIdTesting: false,
|
||||
|
||||
passBooleans: true,
|
||||
passNumbers: true,
|
||||
|
||||
disableOr: true,
|
||||
};
|
||||
|
||||
export const standardFilterBehaviours: { [id: string]: FilterBehaviour } = {
|
||||
numberFilterBehaviour,
|
||||
stringFilterBehaviour,
|
||||
logicalFilterBehaviour,
|
||||
datetimeFilterBehaviour,
|
||||
mongoFilterBehaviour,
|
||||
firestoreFilterBehaviours,
|
||||
evalFilterBehaviour,
|
||||
};
|
||||
|
||||
@@ -75,6 +75,37 @@ export function parseCellValue(value, editorTypes?: DataEditorTypesBehaviour) {
|
||||
}
|
||||
}
|
||||
|
||||
if (editorTypes?.parseGeopointAsDollar) {
|
||||
const m = value.match(/^([\d\.]+)\s*°\s*([NS]),\s*([\d\.]+)\s*°\s*([EW])$/i);
|
||||
if (m) {
|
||||
let latitude = parseFloat(m[1]);
|
||||
const latDir = m[2].toUpperCase();
|
||||
let longitude = parseFloat(m[3]);
|
||||
const lonDir = m[4].toUpperCase();
|
||||
|
||||
if (latDir === 'S') latitude = -latitude;
|
||||
if (lonDir === 'W') longitude = -longitude;
|
||||
|
||||
return {
|
||||
$geoPoint: {
|
||||
latitude,
|
||||
longitude,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (editorTypes?.parseFsDocumentRefAsDollar) {
|
||||
const trimmedValue = value.replace(/\s/g, '');
|
||||
if (trimmedValue.startsWith('$ref:')) {
|
||||
return {
|
||||
$fsDocumentRef: {
|
||||
documentPath: trimmedValue.slice(5),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (editorTypes?.parseJsonNull) {
|
||||
if (value == 'null') return null;
|
||||
}
|
||||
@@ -246,6 +277,32 @@ export function stringifyCellValue(
|
||||
}
|
||||
}
|
||||
|
||||
if (editorTypes?.parseGeopointAsDollar) {
|
||||
if (value?.$geoPoint) {
|
||||
const { latitude, longitude } = value.$geoPoint;
|
||||
if (_isNumber(latitude) && _isNumber(longitude)) {
|
||||
const latAbs = Math.abs(latitude);
|
||||
const lonAbs = Math.abs(longitude);
|
||||
const latDir = latitude >= 0 ? 'N' : 'S';
|
||||
const lonDir = longitude >= 0 ? 'E' : 'W';
|
||||
|
||||
return {
|
||||
value: `${latAbs}° ${latDir}, ${lonAbs}° ${lonDir}`,
|
||||
gridStyle: 'valueCellStyle',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (editorTypes?.parseFsDocumentRefAsDollar) {
|
||||
if (value?.$fsDocumentRef) {
|
||||
return {
|
||||
value: `$ref: ${value.$fsDocumentRef.documentPath ?? ''}`,
|
||||
gridStyle: 'valueCellStyle',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (_isArray(value)) {
|
||||
switch (intent) {
|
||||
case 'gridCellIntent':
|
||||
|
||||
Reference in New Issue
Block a user