{"_id":"@cretezy/cloudflare-d1-backup","_rev":"3-903a30f063c7fa86619f304d6578f052","name":"@cretezy/cloudflare-d1-backup","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"@cretezy/cloudflare-d1-backup","main":"dist/index.js","version":"0.1.0","type":"module","bin":{"cloudflare-d1-backup":"dist/cli.js"},"types":"./dist/index.d.ts","devDependencies":{"@types/node":"^20.8.4","ts-node":"^10.9.1","typescript":"^5.2.2"},"dependencies":{"dotenv":"^16.3.1","node-fetch":"^3.3.2"},"scripts":{"build":"tsc","start":"ts-node-esm src/cli.ts"},"description":"This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat","_id":"@cretezy/cloudflare-d1-backup@0.1.0","_integrity":"sha512-hrI8Audq4FqMih1KBMwQ7u36HllmYdSMaTEQSCysMUWIrMc6Ms9gk3mhM4y3Dnu0c2sebCQHGP1Cls2SyoB2cA==","_resolved":"/private/var/folders/g5/5wgb47bj6blf0hdzrjtctyhm0000gn/T/ef666d71e31a89c9082db3ea2f9287d6/cretezy-cloudflare-d1-backup-0.1.0.tgz","_from":"file:cretezy-cloudflare-d1-backup-0.1.0.tgz","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-hrI8Audq4FqMih1KBMwQ7u36HllmYdSMaTEQSCysMUWIrMc6Ms9gk3mhM4y3Dnu0c2sebCQHGP1Cls2SyoB2cA==","shasum":"81e75d2f3de0e779d33f275e1684e5b1ce355202","tarball":"https://registry.npmjs.org/@cretezy/cloudflare-d1-backup/-/cloudflare-d1-backup-0.1.0.tgz","fileCount":8,"unpackedSize":13941,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpOibFIFcutHkywkxO07REgBe4Pcketyu9qjwsjbyuNwIhAOOpu55mILlRnbR0tZUv4bJXvVVe1vB3pts5JcS1hFiO"}]},"_npmUser":{"name":"cretezy","email":"charles@cretezy.com"},"directories":{},"maintainers":[{"name":"cretezy","email":"charles@cretezy.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-d1-backup_0.1.0_1696914238646_0.5832289576383589"},"_hasShrinkwrap":false},"0.1.1":{"name":"@cretezy/cloudflare-d1-backup","main":"dist/index.js","version":"0.1.1","type":"module","bin":{"cloudflare-d1-backup":"dist/cli.js"},"types":"./dist/index.d.ts","devDependencies":{"@types/node":"^20.8.4","ts-node":"^10.9.1","typescript":"^5.2.2"},"dependencies":{"dotenv":"^16.3.1","node-fetch":"^3.3.2"},"scripts":{"build":"tsc","start":"ts-node-esm src/cli.ts"},"description":"This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat","_id":"@cretezy/cloudflare-d1-backup@0.1.1","_integrity":"sha512-HguZDM2QRwkE/zA6vuvFQXq9l4pJpCB7QlG96WZcHL7vDwP+Gsw5RozBDEMt3bi1W0MZRKko9qZ7UClKjvEjqQ==","_resolved":"/private/var/folders/g5/5wgb47bj6blf0hdzrjtctyhm0000gn/T/0a09ded61d1140f06386ec3bc474ba20/cretezy-cloudflare-d1-backup-0.1.1.tgz","_from":"file:cretezy-cloudflare-d1-backup-0.1.1.tgz","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-HguZDM2QRwkE/zA6vuvFQXq9l4pJpCB7QlG96WZcHL7vDwP+Gsw5RozBDEMt3bi1W0MZRKko9qZ7UClKjvEjqQ==","shasum":"e921191347aa5a2c009ceccec081b3dd4d284954","tarball":"https://registry.npmjs.org/@cretezy/cloudflare-d1-backup/-/cloudflare-d1-backup-0.1.1.tgz","fileCount":8,"unpackedSize":13813,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCeWWqlaUF03qTfP5PWZPynjuVQ93/aS2JM/aTy6X5VuwIgG6gcRQz33pqhIpFNZbPKZ2tOiXTYEI5iye6ODFJYqV0="}]},"_npmUser":{"name":"cretezy","email":"charles@cretezy.com"},"directories":{},"maintainers":[{"name":"cretezy","email":"charles@cretezy.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-d1-backup_0.1.1_1696951716686_0.7252537548396867"},"_hasShrinkwrap":false},"0.2.0":{"name":"@cretezy/cloudflare-d1-backup","main":"dist/index.js","version":"0.2.0","license":"Apache-2.0","type":"module","bin":{"cloudflare-d1-backup":"dist/cli.js"},"types":"./dist/index.d.ts","devDependencies":{"@types/node":"^20.8.4","prettier":"^3.0.3","ts-node":"^10.9.1","typescript":"^5.2.2"},"dependencies":{"dotenv":"^16.3.1","node-fetch":"^3.3.2"},"scripts":{"build":"tsc","start":"ts-node-esm src/cli.ts","format":"prettier -w ."},"description":"This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat","_id":"@cretezy/cloudflare-d1-backup@0.2.0","_integrity":"sha512-puVWbN/sRPZeZDitLBBRaQPiA7ZxYar/DZqOW0iZeypxdOGi6b0IETDvwLd2+m/SOUGh3eccR8KPPnibHuKsJA==","_resolved":"/private/var/folders/g5/5wgb47bj6blf0hdzrjtctyhm0000gn/T/28bb461f1c7ff1fe21ec0c250c7fa58c/cretezy-cloudflare-d1-backup-0.2.0.tgz","_from":"file:cretezy-cloudflare-d1-backup-0.2.0.tgz","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-puVWbN/sRPZeZDitLBBRaQPiA7ZxYar/DZqOW0iZeypxdOGi6b0IETDvwLd2+m/SOUGh3eccR8KPPnibHuKsJA==","shasum":"e1899caa5451d8da9f045572e3fd6f2d7692901e","tarball":"https://registry.npmjs.org/@cretezy/cloudflare-d1-backup/-/cloudflare-d1-backup-0.2.0.tgz","fileCount":9,"unpackedSize":17436,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDGh35fJRW4yFpU8PC1qosdTVIR9PqW5t1wJ02rLxyADQIgIqMZB5FMxMW7qj8+wPxyf+R0dU3CC11ICdvr5BSU8WY="}]},"_npmUser":{"name":"cretezy","email":"charles@cretezy.com"},"directories":{},"maintainers":[{"name":"cretezy","email":"charles@cretezy.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-d1-backup_0.2.0_1699284841403_0.831625910903167"},"_hasShrinkwrap":false},"0.2.1":{"name":"@cretezy/cloudflare-d1-backup","main":"dist/index.js","version":"0.2.1","license":"Apache-2.0","type":"module","bin":{"cloudflare-d1-backup":"dist/cli.js"},"types":"./dist/index.d.ts","devDependencies":{"@types/node":"^20.8.4","prettier":"^3.0.3","ts-node":"^10.9.1","typescript":"^5.2.2"},"dependencies":{"dotenv":"^16.3.1","node-fetch":"^3.3.2"},"scripts":{"build":"tsc","start":"ts-node-esm src/cli.ts","format":"prettier -w ."},"description":"This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat","_id":"@cretezy/cloudflare-d1-backup@0.2.1","_integrity":"sha512-YfygtCJkIwhDG64sqDlx5+c6Jkdk48BsWeAbQK0UQ/4Fdyk56v0Ura2Vi1OCFcMzzjerlOQGECDQqzekF8mmow==","_resolved":"/tmp/9b6f44cdc8f769145489f3a371b03330/cretezy-cloudflare-d1-backup-0.2.1.tgz","_from":"file:cretezy-cloudflare-d1-backup-0.2.1.tgz","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-YfygtCJkIwhDG64sqDlx5+c6Jkdk48BsWeAbQK0UQ/4Fdyk56v0Ura2Vi1OCFcMzzjerlOQGECDQqzekF8mmow==","shasum":"9afb2d69ad99570fee5c8e32834d601eaad428c7","tarball":"https://registry.npmjs.org/@cretezy/cloudflare-d1-backup/-/cloudflare-d1-backup-0.2.1.tgz","fileCount":9,"unpackedSize":17454,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqLtC/C/zaFWxi6VMdtCMVsPPZjcAbCWtbXhuciA/LMQIgTVDYPZn5CxbnRXXgH2V/PtJhjx5Vx2HhkAkphA5UISI="}]},"_npmUser":{"name":"cretezy","email":"charles@cretezy.com"},"directories":{},"maintainers":[{"name":"cretezy","email":"charles@cretezy.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-d1-backup_0.2.1_1703186968769_0.39012806593602334"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-10T05:03:58.496Z","0.1.0":"2023-10-10T05:03:58.843Z","modified":"2023-12-21T19:29:29.105Z","0.1.1":"2023-10-10T15:28:37.006Z","0.2.0":"2023-11-06T15:34:01.609Z","0.2.1":"2023-12-21T19:29:28.920Z"},"maintainers":[{"name":"cretezy","email":"charles@cretezy.com"}],"description":"This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat","readme":"# Cloudflare D1 Backup\n\nThis script creates an backup/export of a Cloudflare D1 SQLite database. It uses\nthe\n[D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database)\nto query for table definitions and data, then outputs SQL commands to recreate\nthe database as-is.\n\nThis script has only been tested on small databases (~700KB). Please report any\nbugs using\n[GitHub Issues](https://github.com/Cretezy/cloudflare-d1-backup/issues).\n\nBased on\n[nora-soderlund/cloudflare-d1-backups](https://github.com/nora-soderlund/cloudflare-d1-backups),\nwhich requires to be ran inside a Worker. This repository uses the\n[D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database).\n\n## Usage\n\nTo create a backup, you must obtain:\n\n- Your Cloudflare account ID. This can be found as the ID in the URL on the\n  dashboard after `dash.cloudflare.com/`, or in the sidebar of a zone.\n- Your Cloudflare D1 database ID. This can be found on the D1 page.\n- Your Cloudflare API key. This can be created under the user icon in the\n  top-right under \"My Profile\", then \"API Tokens\" in the sidebar. Make sure to\n  have D1 write access (the script does not write to your database).\n\n### CLI\n\nThis will create the backup at `backup.sql`.\n\n```bash\nCLOUDFLARE_D1_ACCOUNT_ID=... CLOUDFLARE_D1_DATABASE_ID=... CLOUDFLARE_D1_API_KEY=... \\\nnpx @cretezy/cloudflare-d1-backup backup.sql\n```\n\nThe CLI also supports reading from `.env`.\n\nYou may also pass the `--limit` to add a LIMIT clause for each SELECT query.\nDefault is 1000. You may need to lower if D1 crashes due to\n`Isolate Has exceeded Memory Size`. You can increase to speed up exports.\n\n### Library\n\n```bash\nnpm i @cretezy/cloudflare-d1-backup\n```\n\n```ts\nimport { createBackup } from \"@cretezy/cloudflare-d1-backup\";\n\nconst backup = await createBackup({\n  accountId: \"...\",\n  databaseId: \"...\",\n  apiKey: \"...\",\n  // Optional, see note above on --limit\n  limit: 1000,\n});\n```\n\n`backup` will be the string of the backup commands.\n\n## Restoring a backup\n\n```bash\nnpx wrangler d1 execute <database> --file=<backup.sql>\n```\n\n`<database>` must be the ID or name of the D1 database.\n","readmeFilename":"README.md","license":"Apache-2.0"}