Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for turso integration #2

Open
lklyne opened this issue Jun 18, 2024 · 1 comment
Open

Docs for turso integration #2

lklyne opened this issue Jun 18, 2024 · 1 comment

Comments

@lklyne
Copy link

lklyne commented Jun 18, 2024

First off, thanks for creating this! Exactly what i've been looking for. Great to see some recent updates too.

I'm trying to get things set up on the Turso database fork. Have everything running locally but not sure how to publish to turso.

@renchris
Copy link
Owner

Hi @lklyne ,

Thanks so much for your kind words. I apologize for missing your issue comment here. If you're still blocked and working on this let me know what exactly you're stuck with and I can go over it with you and then create docs for it.

You need to create a Turso account and have your .env variables available for the creating the Turso client, namely the TURSO_ORGANIZATION_URL, TURSO_AUTH_TOKEN, and the TURSO_PARENT_SCHEMA_DATABASE_URL

const getDB = async (): Promise<LibSQLDatabase<typeof schema>> => {
  let url: string
  let authToken: string | undefined
  let turso: Client

  if (process.env.secrets) {
    const secretObject = JSON.parse(process.env.secrets)
    url = secretObject.TURSO_PARENT_SCHEMA_DATABASE_URL
    authToken = secretObject.TURSO_AUTH_TOKEN
  } else if (process.env.NODE_ENV === 'production') {
    const subdomain = await getSubdomain()
    url = `libsql://${subdomain}${process.env.TURSO_ORGANIZATION_URL}` || ''
    authToken = process.env.TURSO_AUTH_TOKEN || ''
  } else {
    url = 'file:sqlite.db'
    authToken = undefined
  }

  try {
    turso = createClient({ url, authToken })
  } catch (err) {
    const createClientError = err as Error
    throw new Error(createClientError.message)
  }

  const db: LibSQLDatabase<typeof schema> = drizzle(turso, { schema })

  return db
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants