{"id":13629014,"url":"https://github.com/theopensource-company/surrealdb-cloudflare","last_synced_at":"2025-04-17T04:32:48.489Z","repository":{"id":59101080,"uuid":"535263730","full_name":"theopensource-company/surrealdb-cloudflare","owner":"theopensource-company","description":"SurrealDB on the edge!","archived":true,"fork":false,"pushed_at":"2022-10-09T14:55:48.000Z","size":50,"stargazers_count":37,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T03:03:58.306Z","etag":null,"topics":["cloudflare-worker","cloudflare-workers","nodejs","rest","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@theopensource-company/surrealdb-cloudflare","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theopensource-company.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-11T10:33:15.000Z","updated_at":"2024-12-15T09:08:04.000Z","dependencies_parsed_at":"2023-01-19T17:04:07.828Z","dependency_job_id":null,"html_url":"https://github.com/theopensource-company/surrealdb-cloudflare","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopensource-company%2Fsurrealdb-cloudflare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopensource-company%2Fsurrealdb-cloudflare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopensource-company%2Fsurrealdb-cloudflare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopensource-company%2Fsurrealdb-cloudflare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theopensource-company","download_url":"https://codeload.github.com/theopensource-company/surrealdb-cloudflare/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249316019,"owners_count":21249878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-worker","cloudflare-workers","nodejs","rest","typescript"],"created_at":"2024-08-01T22:01:01.548Z","updated_at":"2025-04-17T04:32:43.992Z","avatar_url":"https://github.com/theopensource-company.png","language":"TypeScript","funding_links":[],"categories":["Client libraries"],"sub_categories":[],"readme":"# surrealdb-cloudflare\nSurrealDB on the edge!\n\n## Cloudflare workers\nThis module has been build specifically to be compatible with cloudflare workers. Tested with wrangler2, though should probably work fine with wrangler1 aswell.\n\n## Basic interpetation\nIt's just a basic interpetation of the SurrealDB HTTP/REST API, You can check them here: https://surrealdb.com/docs/integration/http\n\n## Get started\nYou can check out the demo.ts file or check the examples down below:\n\n-----\n### Connection variables from environment\n```typescript\nimport Surreal from 'surrealdb-cloudflare';\n\n// Type safety, typescript example :D\ntype Env = {\n    HOST: string;\n    USER: string;\n    PASS: string;\n    NAMESPACE: string;\n    DATABASE: string;\n}\n\n// We can update the connection variables later on, as we don't have them available here just yet...\nconst db = new Surreal();\n\nexport default {\n\tasync fetch(\n\t\trequest: Request,\n        env: Env\n\t): Promise\u003cResponse\u003e {\n        // If database not yet connected, let's update the connection details.\n        if (!db.connected()) db.connect({\n            host: env.HOST ?? '',\n            username: env.USER ?? '',\n            password: env.PASS ?? '',\n            namespace: env.NAMESPACE ?? '',\n            database: env.DATABASE ?? ''\n        });\n\n        // Example query: Retrieves all records from table 'table'.\n        let res = await db.getRecords('table');\n\t\tconsole.log(res[0].result);\n\n\t\treturn new Response(\"Hello World!\");\n\t},\n};\n```\n\n-----\n### Connection variables defined in code\n```typescript\nimport Surreal from 'surrealdb-cloudflare';\n\n// We can update the connection variables later on, as we don't have them available here just yet...\nconst db = new Surreal({\n    host: 'http://surreal.domain.com',\n    username: 'root',\n    password: 'password',\n    namespace: 'awesome',\n    database: 'example'\n});\n\nexport default {\n\tasync fetch(\n\t\trequest: Request\n\t): Promise\u003cResponse\u003e {\n        // Example query: Retrieves all records from table 'table'.\n        let res = await db.getRecords('table');\n\t\tconsole.log(res[0].result);\n\n\t\treturn new Response(\"Hello World!\");\n\t},\n};\n```\n\n## Strong type result\n\n```typescript\nconst res = await db.getRecords\u003c{\n    id: string;\n    username: string;\n    status: \"verified\" | \"unverified\";\n}\u003e('user');\n\nres.forEach(record =\u003e {\n    // Everything in \"result\" is now strong typed with the defined type.\n    const { result } = record;\n    console.log(`${result.id} - User ${result.username} is ${result.status}`);\n});\n```\n\n## Exported types and classes\n\n- `type SurrealConfig`\n- `type SurrealResponse`\n- `(default) class Surreal`\n\n## Available functions in Surreal class\n\n- `Surreal.connect(config: SurrealConfig)`: Update connection details to Surreal database.\n- `Surreal.connected(): boolean`: Check if connection details are successfully specified.\n\n### All functions in the following section return the following:\n```typescript\n    [\n        {\n            time: string;\n            status: string;\n            result: TResponse;\n        },\n        ....\n    ]\n```\n- `async Surreal.query(query: string)`: Run a query on the specified database.\n- `async Surreal.getRecords(table: string)`: Get all records from table.\n- `async Surreal.createRecord(table: string, data: object)`: Create a record with random ID.\n- `async Surreal.deleteRecords(table: string)`: Delete all records from table.\n- `async Surreal.getRecordWithId(table: string, id: string)`: Get record from table with ID.\n- `async Surreal.createRecordWithId(table: string, id: string, data: object)`: Create record in table with ID.\n- `async Surreal.setRecordWithId(table: string, id: string, data: object)`: Overwrite record in table with ID.\n- `async Surreal.updateRecordWithId(table: string, id: string, data: object)`: Update record in table with ID.\n- `async Surreal.deleteRecordWithId(table: string, id: string)`: Delete record from table with ID.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopensource-company%2Fsurrealdb-cloudflare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopensource-company%2Fsurrealdb-cloudflare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopensource-company%2Fsurrealdb-cloudflare/lists"}