rsnext/examples/with-xata/utils/xata.codegen.ts
Alexis Rico a45bf8c93b
Fix deploy button in with-xata example (#43608)
The deploy button of the `with-xata` example is not working properly
because we were lacking the integration to configure the env variables.

[![Deploy with
Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/SferaDev/nextjs-demo/tree/fix-with-xata-deploy/examples/with-xata&project-name=with-xata&repository-name=with-xata&integration-ids=oac_IDpMECDuYqBvAtu3wXXMQe0J)

Taking advantage of the PR, some other changes:

- Adding `alt` to `next/image` to fix build with latest version
- Update readme to add more information in the Xata CLI section
- Use a new command to initialize the database schema on first
deployment
- Remove hardcoded URL in `xata.codegen.ts`
- Remove deprecated `formatVersion` in `schema.template.json`
- Update dependencies

Note: The integration is still work in progress, it works for the
`Deploy to Vercel` button but we want to improve the UI/UX before
submitting it to the Marketplace, keeping it unlisted for a while.
2022-12-01 11:34:23 -08:00

41 lines
989 B
TypeScript

import {
BaseClientOptions,
buildClient,
SchemaInference,
XataRecord,
} from '@xata.io/client'
const tables = [
{
name: 'nextjs_with_xata_example',
columns: [
{ name: 'title', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'url', type: 'string' },
],
},
] as const
export type SchemaTables = typeof tables
export type DatabaseSchema = SchemaInference<SchemaTables>
export type NextjsWithXataExample = DatabaseSchema['nextjs_with_xata_example']
export type NextjsWithXataExampleRecord = NextjsWithXataExample & XataRecord
const DatabaseClient = buildClient()
const defaultOptions = {}
export class XataClient extends DatabaseClient<SchemaTables> {
constructor(options?: BaseClientOptions) {
super({ ...defaultOptions, ...options }, tables)
}
}
let instance: XataClient | undefined = undefined
export const getXataClient = () => {
if (instance) return instance
instance = new XataClient()
return instance
}