@@ -157,8 +157,7 @@ describe('xata init', () => {
157157 }",
158158 "package.json": "{"name":"test","version":"1.0.0"}",
159159 "readme.md": "",
160- "xataCustom.ts": "// Generated by Xata Codegen 0.29.4. Please do not edit.
161- import { buildClient } from "@xata.io/client";
160+ "xataCustom.ts": "import { buildClient, getDeployPreviewBranch } from "@xata.io/client";
162161 import type {
163162 BaseClientOptions,
164163 SchemaInference,
@@ -181,24 +180,23 @@ describe('xata init', () => {
181180
182181 const DatabaseClient = buildClient();
183182
184- const defaultOptions = {
185- databaseURL: "https://test-1234.us-east-1.xata.sh/db/db1",
186- };
187-
188183 export class XataClient extends DatabaseClient<DatabaseSchema> {
189184 constructor(options?: BaseClientOptions) {
190- super({ ...defaultOptions, ...options }, tables);
185+ super(
186+ {
187+ apiKey: process.env.XATA_API_KEY,
188+ databaseURL: process.env.XATA_DATABASE_URL,
189+ // Use deploy preview branch if available, otherwise use branch from environment
190+ branch:
191+ getDeployPreviewBranch(process.env) ??
192+ process.env.XATA_BRANCH ??
193+ "main",
194+ ...options,
195+ },
196+ tables
197+ );
191198 }
192199 }
193-
194- let instance: XataClient | undefined = undefined;
195-
196- export const getXataClient = () => {
197- if (instance) return instance;
198-
199- instance = new XataClient();
200- return instance;
201- };
202200 ",
203201 }
204202 ` ) ;
@@ -242,8 +240,7 @@ describe('xata init', () => {
242240 }
243241 }",
244242 "readme.md": "",
245- "xataCustom.ts": "// Generated by Xata Codegen 0.29.4. Please do not edit.
246- import { buildClient } from "@xata.io/client";
243+ "xataCustom.ts": "import { buildClient, getDeployPreviewBranch } from "@xata.io/client";
247244 import type {
248245 BaseClientOptions,
249246 SchemaInference,
@@ -266,24 +263,23 @@ describe('xata init', () => {
266263
267264 const DatabaseClient = buildClient();
268265
269- const defaultOptions = {
270- databaseURL: "https://test-1234.us-east-1.xata.sh/db/db1",
271- };
272-
273266 export class XataClient extends DatabaseClient<DatabaseSchema> {
274267 constructor(options?: BaseClientOptions) {
275- super({ ...defaultOptions, ...options }, tables);
268+ super(
269+ {
270+ apiKey: process.env.XATA_API_KEY,
271+ databaseURL: process.env.XATA_DATABASE_URL,
272+ // Use deploy preview branch if available, otherwise use branch from environment
273+ branch:
274+ getDeployPreviewBranch(process.env) ??
275+ process.env.XATA_BRANCH ??
276+ "main",
277+ ...options,
278+ },
279+ tables
280+ );
276281 }
277282 }
278-
279- let instance: XataClient | undefined = undefined;
280-
281- export const getXataClient = () => {
282- if (instance) return instance;
283-
284- instance = new XataClient();
285- return instance;
286- };
287283 ",
288284 }
289285 ` ) ;
@@ -319,8 +315,10 @@ describe('xata init', () => {
319315 }
320316 }",
321317 "readme.md": "",
322- "xataCustom.ts": "// Generated by Xata Codegen 0.29.4. Please do not edit.
323- import { buildClient } from "npm:@xata.io/client@latest";
318+ "xataCustom.ts": "import {
319+ buildClient,
320+ getDeployPreviewBranch,
321+ } from "npm:@xata.io/client@latest";
324322 import type {
325323 BaseClientOptions,
326324 SchemaInference,
@@ -343,24 +341,23 @@ describe('xata init', () => {
343341
344342 const DatabaseClient = buildClient();
345343
346- const defaultOptions = {
347- databaseURL: "https://test-1234.us-east-1.xata.sh/db/db1",
348- };
349-
350344 export class XataClient extends DatabaseClient<DatabaseSchema> {
351345 constructor(options?: BaseClientOptions) {
352- super({ ...defaultOptions, ...options }, tables);
346+ super(
347+ {
348+ apiKey: Deno.env.get("XATA_API_KEY"),
349+ databaseURL: Deno.env.get("XATA_DATABASE_URL"),
350+ // Use deploy preview branch if available, otherwise use branch from environment
351+ branch:
352+ getDeployPreviewBranch(Deno.env.get) ??
353+ Deno.env.get("XATA_BRANCH") ??
354+ "main",
355+ ...options,
356+ },
357+ tables
358+ );
353359 }
354360 }
355-
356- let instance: XataClient | undefined = undefined;
357-
358- export const getXataClient = () => {
359- if (instance) return instance;
360-
361- instance = new XataClient();
362- return instance;
363- };
364361 ",
365362 }
366363 ` ) ;
@@ -400,8 +397,7 @@ describe('xata init', () => {
400397 "package.json": "{"name":"test","version":"1.0.0"}",
401398 "pnpm-lock.yaml": "lockfileVersion: '6.0'",
402399 "readme.md": "",
403- "xataCustom.ts": "// Generated by Xata Codegen 0.29.4. Please do not edit.
404- import { buildClient } from "@xata.io/client";
400+ "xataCustom.ts": "import { buildClient, getDeployPreviewBranch } from "@xata.io/client";
405401 import type {
406402 BaseClientOptions,
407403 SchemaInference,
@@ -424,24 +420,23 @@ describe('xata init', () => {
424420
425421 const DatabaseClient = buildClient();
426422
427- const defaultOptions = {
428- databaseURL: "https://test-1234.us-east-1.xata.sh/db/db1",
429- };
430-
431423 export class XataClient extends DatabaseClient<DatabaseSchema> {
432424 constructor(options?: BaseClientOptions) {
433- super({ ...defaultOptions, ...options }, tables);
425+ super(
426+ {
427+ apiKey: process.env.XATA_API_KEY,
428+ databaseURL: process.env.XATA_DATABASE_URL,
429+ // Use deploy preview branch if available, otherwise use branch from environment
430+ branch:
431+ getDeployPreviewBranch(process.env) ??
432+ process.env.XATA_BRANCH ??
433+ "main",
434+ ...options,
435+ },
436+ tables
437+ );
434438 }
435439 }
436-
437- let instance: XataClient | undefined = undefined;
438-
439- export const getXataClient = () => {
440- if (instance) return instance;
441-
442- instance = new XataClient();
443- return instance;
444- };
445440 ",
446441 }
447442 ` ) ;
0 commit comments