MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / constructor

Method constructor

packages/orm/src/client/client-impl.ts:74–143  ·  view source on GitHub ↗
(
        private readonly schema: SchemaDef,
        private options: ClientOptions<SchemaDef>,
        baseClient?: ClientImpl,
        executor?: QueryExecutor,
    )

Source from the content-addressed store, hash-verified

72 readonly slowQueries: QueryInfo[] = [];
73
74 constructor(
75 private readonly schema: SchemaDef,
76 private options: ClientOptions<SchemaDef>,
77 baseClient?: ClientImpl,
78 executor?: QueryExecutor,
79 ) {
80 this.$schema = schema;
81 this.$options = options;
82
83 this.$options.functions = {
84 ...BuiltinFunctions,
85 ...this.$options.functions,
86 };
87
88 this.validateOptions(baseClient, options);
89
90 // here we use kysely's props constructor so we can pass a custom query executor
91 if (baseClient) {
92 this.kyselyProps = {
93 ...baseClient.kyselyProps,
94 executor:
95 executor ??
96 new ZenStackQueryExecutor(
97 this,
98 baseClient.kyselyProps.driver as ZenStackDriver,
99 baseClient.kyselyProps.dialect.createQueryCompiler(),
100 baseClient.kyselyProps.dialect.createAdapter(),
101 new DefaultConnectionProvider(baseClient.kyselyProps.driver),
102 ),
103 };
104 this.kyselyRaw = baseClient.kyselyRaw;
105 this.auth = baseClient.auth;
106 this.slowQueries = baseClient.slowQueries;
107 } else {
108 const driver = new ZenStackDriver(options.dialect.createDriver(), new Log(this.$options.log ?? []));
109 const compiler = options.dialect.createQueryCompiler();
110 const adapter = options.dialect.createAdapter();
111 const connectionProvider = new DefaultConnectionProvider(driver);
112
113 this.kyselyProps = {
114 config: {
115 dialect: options.dialect,
116 log: this.$options.log,
117 },
118 dialect: options.dialect,
119 driver,
120 executor: executor ?? new ZenStackQueryExecutor(this, driver, compiler, adapter, connectionProvider),
121 };
122
123 // raw kysely instance with default executor
124 this.kyselyRaw = new Kysely({
125 ...this.kyselyProps,
126 executor: new DefaultQueryExecutor(compiler, adapter, connectionProvider, []),
127 });
128 }
129
130 if (baseClient?.isTransaction && !executor) {
131 // if we're creating a derived client from a transaction client and not replacing

Callers

nothing calls this directly

Calls 2

validateOptionsMethod · 0.95
createClientProxyFunction · 0.85

Tested by

no test coverage detected