@@ -25,6 +25,8 @@ import { AnalyticsServicePlugin } from '@objectstack/service-analytics';
2525import CrmApp from '../../examples/app-crm/objectstack.config' ;
2626import TodoApp from '../../examples/app-todo/objectstack.config' ;
2727import BiPluginManifest from '../../examples/plugin-bi/objectstack.config' ;
28+ import { fileURLToPath } from 'node:url' ;
29+ import { dirname , resolve } from 'node:path' ;
2830
2931// Resolve base URL: explicit env > Vercel production URL > Vercel preview URL > localhost
3032const baseUrl = process . env . NEXT_PUBLIC_BASE_URL
@@ -35,12 +37,21 @@ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL
3537 ?? 'http://localhost:3000' ;
3638
3739// Turso driver for sys namespace — remote when env vars are configured, local SQLite otherwise
40+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
3841const tursoDriver = new TursoDriver (
3942 process . env . TURSO_DATABASE_URL
4043 ? { url : process . env . TURSO_DATABASE_URL , authToken : process . env . TURSO_AUTH_TOKEN }
41- : { url : ' file:.objectstack/data/dev.db' } ,
44+ : { url : ` file:${ resolve ( __dirname , ' .objectstack/data/dev.db') } ` } ,
4245) ;
4346
47+ // Datasource routing: sys namespace → turso, everything else → memory
48+ const datasourceMapping = [
49+ { namespace : 'sys' , datasource : 'com.objectstack.driver.turso' } ,
50+ { default : true , datasource : 'com.objectstack.driver.memory' } ,
51+ ] ;
52+
53+ const oqlPlugin = new ObjectQLPlugin ( ) ;
54+
4455export default defineStack ( {
4556 manifest : {
4657 id : 'com.objectstack.server' ,
@@ -51,7 +62,15 @@ export default defineStack({
5162 type : 'app' ,
5263 } ,
5364 plugins : [
54- new ObjectQLPlugin ( ) ,
65+ oqlPlugin ,
66+ // Set datasourceMapping right after ObjectQL init — access ql instance directly
67+ {
68+ name : 'datasource-mapping' ,
69+ init ( ) {
70+ const ql = ( oqlPlugin as any ) . ql ;
71+ if ( ql ?. setDatasourceMapping ) ql . setDatasourceMapping ( datasourceMapping ) ;
72+ } ,
73+ } ,
5574 new DriverPlugin ( new InMemoryDriver ( ) , 'memory' ) ,
5675 new DriverPlugin ( tursoDriver , 'turso' ) ,
5776 new AppPlugin ( CrmApp ) ,
@@ -70,8 +89,5 @@ export default defineStack({
7089 new AutomationServicePlugin ( ) ,
7190 new AnalyticsServicePlugin ( ) ,
7291 ] ,
73- datasourceMapping : [
74- { namespace : 'sys' , datasource : 'turso' } ,
75- { default : true , datasource : 'memory' } ,
76- ] ,
77- } ) ;
92+ datasourceMapping,
93+ } , { strict : false } ) ;
0 commit comments