| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 621779b commit 3c815a2
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,20 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData | |||
| 9 | 9 | ||
| 10 | 10 | async setupClient(url: string): Promise<void> { | |
| 11 | 11 | this.client = betterSqlite3(url.replace('sqlite://', '')); | |
| 12 | + this.client.aggregate('median', { | ||
| 13 | + start: (): number[] => [], | ||
| 14 | + step: (acc: number[], val: any) => { | ||
| 15 | + if (val != null) acc.push(Number(val)); | ||
| 16 | + }, | ||
| 17 | + result: (acc: number[]): number | null => { | ||
| 18 | + if (acc.length === 0) return null; | ||
| 19 | + const sorted = acc.slice().sort((a, b) => a - b); | ||
| 20 | + const mid = Math.floor(sorted.length / 2); | ||
| 21 | + return sorted.length % 2 === 0 | ||
| 22 | + ? (sorted[mid - 1] + sorted[mid]) / 2 | ||
| 23 | + : sorted[mid]; | ||
| 24 | + }, | ||
| 25 | + }); | ||
| 12 | 26 | } | |
| 13 | 27 | async getAllTables(): Promise<Array<string>> { | |
| 14 | 28 | const stmt = this.client.prepare( | |
@@ -358,7 +372,7 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData | |||
| 358 | 372 | case 'avg': selectParts.push(`AVG("${rule.field}") AS "${alias}"`); break; | |
| 359 | 373 | case 'min': selectParts.push(`MIN("${rule.field}") AS "${alias}"`); break; | |
| 360 | 374 | case 'max': selectParts.push(`MAX("${rule.field}") AS "${alias}"`); break; | |
| 361 | - case 'median': throw new Error('Aggregates.median() with GroupBy.Field is not supported in SQLite.'); | ||
| 375 | + case 'median': selectParts.push(`median("${rule.field}") AS "${alias}"`); break; | ||
| 362 | 376 | } | |
| 363 | 377 | } | |
| 364 | 378 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments