-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fed779
commit 7f5ca7e
Showing
6 changed files
with
445 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# The following is a sample a .env file, to get started create a copy and name | ||
# it ".env". | ||
|
||
NODE_ENV=development | ||
|
||
# Must match NEXTAUTH_SECRET on front-end as it is used to sign and validate JWTs | ||
AUTH_SECRET=secret | ||
|
||
TURSO_DATABASE_URL=file:../../local.db | ||
|
||
# Production | ||
|
||
# NODE_ENV=production | ||
# TURSO_AUTH_TOKEN= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { DatabaseConfiguration } from "@hocuspocus/extension-database"; | ||
import { createClient } from "@libsql/client"; | ||
import { env } from "./env.js"; | ||
|
||
const client = createClient({ | ||
url: env.TURSO_DATABASE_URL, | ||
authToken: env.TURSO_AUTH_TOKEN, | ||
}); | ||
|
||
const tursoConfiguration: DatabaseConfiguration = { | ||
async fetch({ documentName }) { | ||
const res = await client.execute({ | ||
sql: `SELECT name, data | ||
FROM document | ||
WHERE name = ? | ||
`, | ||
args: [documentName], | ||
}); | ||
|
||
const data = res.rows[0]?.data; | ||
if (data instanceof ArrayBuffer) { | ||
return new Uint8Array(data); | ||
} | ||
|
||
return null; | ||
}, | ||
|
||
async store({ documentName, state: documentData }) { | ||
const now = new Date().getTime(); | ||
await client.execute({ | ||
sql: `UPDATE document | ||
SET data = ?, | ||
modifiedOn = ? | ||
WHERE name = ? | ||
`, | ||
args: [documentName, now, documentData], | ||
}); | ||
}, | ||
}; | ||
|
||
export default tursoConfiguration; |
Oops, something went wrong.