Skip to content

Commit 3ae6c68

Browse files
Copilothotlong
andcommitted
Implement QueryService and QueryAnalyzer for Week 4
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent ab44fbd commit 3ae6c68

5 files changed

Lines changed: 958 additions & 1 deletion

File tree

packages/foundation/core/src/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export class ObjectQL implements IObjectQL {
5858
}
5959

6060
// Add the ObjectQL plugin to provide enhanced features
61-
this.kernelPlugins.push(new ObjectQLPlugin());
61+
this.kernelPlugins.push(new ObjectQLPlugin({
62+
datasources: this.datasources
63+
}));
6264

6365
// Add runtime plugins from config
6466
if (config.plugins) {

packages/foundation/core/src/plugin.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import type { RuntimePlugin, RuntimeContext } from '@objectstack/runtime';
1010
import type { ObjectStackKernel } from '@objectstack/runtime';
1111
import { ValidatorPlugin, ValidatorPluginConfig } from './validator-plugin';
1212
import { FormulaPlugin, FormulaPluginConfig } from './formula-plugin';
13+
import { QueryService } from './query/query-service';
14+
import { QueryAnalyzer } from './query/query-analyzer';
15+
import type { Driver } from '@objectql/types';
16+
17+
/**
18+
* Extended ObjectStack Kernel with ObjectQL services
19+
*/
20+
interface ExtendedKernel extends ObjectStackKernel {
21+
queryService?: QueryService;
22+
queryAnalyzer?: QueryAnalyzer;
23+
}
1324

1425
/**
1526
* Configuration for the ObjectQL Plugin
@@ -50,6 +61,18 @@ export interface ObjectQLPluginConfig {
5061
* @default true
5162
*/
5263
enableAI?: boolean;
64+
65+
/**
66+
* Enable query service and analyzer
67+
* @default true
68+
*/
69+
enableQueryService?: boolean;
70+
71+
/**
72+
* Datasources for query service
73+
* Required if enableQueryService is true
74+
*/
75+
datasources?: Record<string, Driver>;
5376
}
5477

5578
/**
@@ -70,6 +93,7 @@ export class ObjectQLPlugin implements RuntimePlugin {
7093
enableValidator: true,
7194
enableFormulas: true,
7295
enableAI: true,
96+
enableQueryService: true,
7397
...config
7498
};
7599
}
@@ -81,6 +105,25 @@ export class ObjectQLPlugin implements RuntimePlugin {
81105
async install(ctx: RuntimeContext): Promise<void> {
82106
console.log(`[${this.name}] Installing plugin...`);
83107

108+
const kernel = ctx.engine as ExtendedKernel;
109+
110+
// Register QueryService and QueryAnalyzer if enabled
111+
if (this.config.enableQueryService !== false && this.config.datasources) {
112+
const queryService = new QueryService(
113+
this.config.datasources,
114+
kernel.metadata
115+
);
116+
kernel.queryService = queryService;
117+
118+
const queryAnalyzer = new QueryAnalyzer(
119+
queryService,
120+
kernel.metadata
121+
);
122+
kernel.queryAnalyzer = queryAnalyzer;
123+
124+
console.log(`[${this.name}] QueryService and QueryAnalyzer registered`);
125+
}
126+
84127
// Register components based on configuration
85128
if (this.config.enableRepository !== false) {
86129
await this.registerRepository(ctx.engine);

packages/foundation/core/src/query/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
* This module contains ObjectQL's query-specific functionality:
1313
* - FilterTranslator: Converts ObjectQL filters to ObjectStack FilterNode
1414
* - QueryBuilder: Builds ObjectStack QueryAST from ObjectQL UnifiedQuery
15+
* - QueryService: Executes queries via drivers with profiling support
16+
* - QueryAnalyzer: Provides query performance analysis and optimization suggestions
1517
*
1618
* These are the core components that differentiate ObjectQL from generic runtime systems.
1719
*/
1820

1921
export * from './filter-translator';
2022
export * from './query-builder';
23+
export * from './query-service';
24+
export * from './query-analyzer';

0 commit comments

Comments
 (0)