Skip to content

Commit f95e70b

Browse files
committed
Add config file and improve studio CLI initialization
Introduces objectql.config.ts for datasource and preset configuration. Updates the studio CLI command to initialize from a config object, supporting SQLite and in-memory datasources. Adjusts studio handler to search additional build paths and updates the npm script for studio. Removes an unused project reference from tsconfig.json.
1 parent 73d7e48 commit f95e70b

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

objectql.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
datasource: {
3+
default: {
4+
type: 'sqlite',
5+
filename: 'objectos.db'
6+
}
7+
},
8+
presets: [
9+
'@objectql/starter-basic',
10+
'@objectql/starter-enterprise'
11+
]
12+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"build": "tsc -b && pnpm -r run build",
66
"check-versions": "node scripts/check-versions.js",
77
"test": "pnpm run check-versions && pnpm -r run test",
8-
"studio": "node packages/cli/dist/index.js studio --dir examples/starters/basic-script",
8+
"studio": "node packages/tools/cli/dist/index.js studio",
99
"changeset": "changeset",
1010
"version": "changeset version",
1111
"release": "pnpm run build && changeset publish",

packages/runtime/server/src/studio.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function createStudioHandler() {
2424
const possiblePaths = [
2525
path.join(__dirname, '../../studio/dist'),
2626
path.join(process.cwd(), 'packages/studio/dist'),
27+
path.join(process.cwd(), 'packages/tools/studio/dist'),
2728
];
2829

2930
for (const p of possiblePaths) {

packages/tools/cli/src/commands/studio.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,49 @@ export async function startStudio(options: { port: number; dir: string, open?: b
7878
process.exit(1);
7979
}
8080

81+
// Initialize App if it's a configuration object
82+
if (typeof (app as any).init !== 'function') {
83+
const config = app as any;
84+
console.log(chalk.gray('Configuration object detected. Initializing ObjectQL instance...'));
85+
86+
const datasources: any = {};
87+
88+
if (config.datasource && config.datasource.default) {
89+
const dbConfig = config.datasource.default;
90+
if (dbConfig.type === 'sqlite') {
91+
try {
92+
const { KnexDriver } = require('@objectql/driver-sql');
93+
datasources.default = new KnexDriver({
94+
client: 'sqlite3',
95+
connection: {
96+
filename: dbConfig.filename ? path.resolve(rootDir, dbConfig.filename) : ':memory:'
97+
},
98+
useNullAsDefault: true
99+
});
100+
} catch (e) {
101+
console.warn(chalk.yellow('Failed to load @objectql/driver-sql. Ensure it is installed.'));
102+
}
103+
}
104+
}
105+
106+
// Fallback to memory if no datasource
107+
if (!datasources.default) {
108+
console.warn(chalk.yellow('No valid datasource found. Using in-memory SQLite.'));
109+
const { KnexDriver } = require('@objectql/driver-sql');
110+
datasources.default = new KnexDriver({
111+
client: 'sqlite3',
112+
connection: { filename: ':memory:' },
113+
useNullAsDefault: true
114+
});
115+
}
116+
117+
app = new ObjectQL({ datasources });
118+
119+
// Load Schema
120+
const loader = new ObjectLoader(app.metadata);
121+
loader.load(rootDir);
122+
}
123+
81124
// 2. Load Schema & Init
82125
try {
83126
await app.init();

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
{ "path": "./packages/starters/express-api" },
1414
{ "path": "./packages/starters/basic" },
1515
{ "path": "./packages/starters/enterprise" },
16-
{ "path": "./examples/plugins/audit-log" },
17-
{ "path": "./examples/scenarios/preset-usage" }
16+
{ "path": "./examples/plugins/audit-log" }
1817
]
1918
}

0 commit comments

Comments
 (0)