{"_id":"@brahimemo/surrealdb-js","_rev":"5-dd935cc8e0b5a6cedf6843634e6c8709","name":"@brahimemo/surrealdb-js","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@brahimemo/surrealdb-js","version":"1.0.0","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"author":{"name":"BrahimEmo"},"license":"MIT","_id":"@brahimemo/surrealdb-js@1.0.0","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"dist":{"shasum":"0ffaf2d292c124985d8da8561dbcecc7436dfbed","tarball":"https://registry.npmjs.org/@brahimemo/surrealdb-js/-/surrealdb-js-1.0.0.tgz","fileCount":5,"integrity":"sha512-9afNgtM+psOihJ8kysIbDKxbF6nK25xMmU6OAKb3NocQqWDBPAVynQQcLM+MpcPlCNgJ5Pd0XVLW+Ue/RG8IoA==","signatures":[{"sig":"MEUCIDltfYAfX1uK8cNtwEnaYgLh0T+wBXyosoNDGylMnWdNAiEA81q2UtcKT9fGk+X1jbb8QM/wtzR3RssnGw4lJfkoe8w=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9357},"main":"index.js","types":"index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"d5641d20a34105d26720bd1887a087899887ccc6","_npmUser":{"name":"brahimemo","email":"brahime373@gmail.com"},"_npmVersion":"10.8.2","description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","directories":{},"_nodeVersion":"21.6.0","dependencies":{"axios":"^1.7.4"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/surrealdb-js_1.0.0_1727295389589_0.5458294332919902","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.1":{"name":"@brahimemo/surrealdb-js","version":"1.0.1","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"author":{"name":"BrahimEmo"},"license":"MIT","_id":"@brahimemo/surrealdb-js@1.0.1","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"dist":{"shasum":"cdf1921a06a937b13fc42d8d2a123ce7a0f6c9a8","tarball":"https://registry.npmjs.org/@brahimemo/surrealdb-js/-/surrealdb-js-1.0.1.tgz","fileCount":5,"integrity":"sha512-6UE7pbPIQB0xwJtyyZfS+iB5tBkdNjttWTqmzRJ2pWMyVslAXoA3NhP9EkPNpMtutGiHLH2BCLDqWiVbBmzspQ==","signatures":[{"sig":"MEQCIEW9yEe9AKFX3YUNDVUnwQErO4bDsEi7F72EWdo+mdlnAiAa/VQYGf/5kpVYQzMSrOwmFqMbfxe1YwEteGiMb4vTFQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9649},"main":"index.js","type":"module","types":"index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"7ce9ad6c097d90c431692654cf09c4c3c0aa260a","_npmUser":{"name":"brahimemo","email":"brahime373@gmail.com"},"_npmVersion":"10.8.2","description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","directories":{},"_nodeVersion":"21.6.0","dependencies":{"axios":"^1.7.4"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^22.7.4"},"_npmOperationalInternal":{"tmp":"tmp/surrealdb-js_1.0.1_1727611388254_0.18344084769145597","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.2":{"name":"@brahimemo/surrealdb-js","version":"1.0.2","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"author":{"name":"BrahimEmo"},"license":"MIT","_id":"@brahimemo/surrealdb-js@1.0.2","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"dist":{"shasum":"c7f0fdcc11555abbbb208617cb3e5b366109a1e9","tarball":"https://registry.npmjs.org/@brahimemo/surrealdb-js/-/surrealdb-js-1.0.2.tgz","fileCount":5,"integrity":"sha512-MU/RYa7ox/f0v5/8cayrHyS7wsBh1lKv+kGFY0koREh5p8AsAHLaUDjqgUXhR3dezaq7MlBhy7dKO74BmTv9Ew==","signatures":[{"sig":"MEYCIQDheV4gePqEptNoyuEQEP3fHFLBQiHsKkvxP3WqfBA8XQIhALhbvstWK8BzPwmkBwBzv1K1nM1x2PsbTiAB9IYg43d1","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9779},"main":"index.js","type":"module","types":"index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"94b83ee25685afa6150212627a5e16872723504b","_npmUser":{"name":"brahimemo","email":"brahime373@gmail.com"},"_npmVersion":"10.8.2","description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","directories":{},"_nodeVersion":"21.6.0","dependencies":{"axios":"^1.7.4"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^22.7.4"},"_npmOperationalInternal":{"tmp":"tmp/surrealdb-js_1.0.2_1727611846644_0.9053572037293545","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.1.0":{"name":"@brahimemo/surrealdb-js","version":"1.1.0","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"author":{"name":"BrahimEmo"},"license":"MIT","_id":"@brahimemo/surrealdb-js@1.1.0","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"dist":{"shasum":"f6f06552a32c199a3fd1ddf52b6ba9c37c83c1bd","tarball":"https://registry.npmjs.org/@brahimemo/surrealdb-js/-/surrealdb-js-1.1.0.tgz","fileCount":6,"integrity":"sha512-MEHt47nXpoIArbqvMcBJS6y/DqTOUMx4nBg5fZMtZzEpNQP1LTKTy4zILPYXeX2SfTeXGxjI+g49pOyc3cu9EQ==","signatures":[{"sig":"MEUCIColIhD7FuJyTudUXwJObc40IaDAgEIZ2ap+4ADj6DtlAiEAqlvsHW6++9rN7udh97o0Q/sY0IukH0lrJOxwJqbelZc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12606},"main":"lib/db/index.cjs","types":"index.d.ts","module":"lib/db/index.mjs","engines":{"node":">=18.0.0"},"gitHead":"1764a2af0f5663639a02e671ed164ebc1ab13511","_npmUser":{"name":"brahimemo","email":"brahime373@gmail.com"},"_npmVersion":"10.8.2","description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","directories":{},"_nodeVersion":"21.6.0","dependencies":{"axios":"^1.7.4"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^22.7.4"},"_npmOperationalInternal":{"tmp":"tmp/surrealdb-js_1.1.0_1727615126118_0.5237584889258204","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.1.1":{"name":"@brahimemo/surrealdb-js","version":"1.1.1","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"author":{"name":"BrahimEmo"},"license":"MIT","_id":"@brahimemo/surrealdb-js@1.1.1","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"dist":{"shasum":"ebceffe9e5cddf8739010a81dd1c84cb53b35b28","tarball":"https://registry.npmjs.org/@brahimemo/surrealdb-js/-/surrealdb-js-1.1.1.tgz","fileCount":6,"integrity":"sha512-+58cev8IaDLf5D0LnK+C2LKwHInysRckq5aA8FLWqetfZgal8sxlyCqJXNaMay3sGDbcl3wioybvbTVZPeXTGA==","signatures":[{"sig":"MEUCIAI8fOUMMCPn38iKJPvJVjcLN2E8nAkTrXqUo08m8l8CAiEAuvufVODwNqlC+BuwG/CZSSQIMpWMj65QawREnDCtL9Q=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12699},"main":"lib/db/index.cjs","types":"index.d.ts","module":"lib/db/index.mjs","engines":{"node":">=18.0.0"},"gitHead":"2be74392e63f472e705a9bd3868573025b08e459","_npmUser":{"name":"brahimemo","email":"brahime373@gmail.com"},"_npmVersion":"10.8.2","description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","directories":{},"_nodeVersion":"21.6.0","dependencies":{"axios":"^1.7.4"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"^22.7.4"},"_npmOperationalInternal":{"tmp":"tmp/surrealdb-js_1.1.1_1727885893251_0.44988160526463106","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2024-09-25T20:16:29.488Z","modified":"2024-11-17T13:08:30.744Z","1.0.0":"2024-09-25T20:16:31.942Z","1.0.1":"2024-09-29T12:03:08.435Z","1.0.2":"2024-09-29T12:10:46.842Z","1.1.0":"2024-09-29T13:05:26.362Z","1.1.1":"2024-10-02T16:18:13.435Z"},"author":{"name":"BrahimEmo"},"license":"MIT","keywords":["surrealdb","javascript","database","client","surrealQL","multi-model","query","authentication"],"description":"A lightweight and efficient JavaScript client for interacting with SurrealDB databases. Supports both v1.x and v2.x+","maintainers":[{"name":"brahimemo","email":"brahime373@gmail.com"}],"readme":"```markdown\r\n# @brahimemo/surrealdb-js\r\n\r\nA lightweight and efficient JavaScript client for interacting with SurrealDB databases.  Supports both v1.x and v2.x+.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm i @brahimemo/surrealdb-js\r\n```\r\n\r\n## Usage\r\n\r\nThis package provides a simple interface for querying a SurrealDB database.\r\n\r\n### Initialization\r\n\r\nFirst, initialize the `SurrealDB` class with your database configuration:\r\n\r\n```typescript\r\nimport SurrealDB from '@brahimemo/surrealdb-js';\r\n\r\nconst db = new SurrealDB({\r\n  url: 'http://localhost:8000', // Your SurrealDB URL\r\n  version: '>= 2.x', // Specify the SurrealDB version (1.x <= or >= 2.x)\r\n  namespace: '<your namespace>',\r\n  database: '<your database>',\r\n  auth: { // Authentication details (optional)\r\n    method: 'Root',\r\n    vars: {\r\n      username: '<your username>',\r\n      password: '<your password>'\r\n    }\r\n  }\r\n});\r\n```\r\n\r\nSupported authentication methods:\r\n\r\n* **`Root`**:  Requires `username` and `password`.  Optionally includes `namespace` and `database` (For `Namespace` Or `Database` User).\r\n* **`Token`**: Requires a `token`.\r\n* **`Scope`**: Requires a `scope` and `vars` (key-value pairs).\r\n* **`Anonymous`**: Auth === undefined.\r\n\r\n### Querying the Database\r\n\r\nUse the `query` method to execute SQL queries:\r\n\r\n```typescript\r\ntype User = {\r\n  id: string;\r\n  name: string;\r\n}\r\nconst [data, error] = await db.query<User[]>(`SELECT * FROM users`);\r\n\r\n// Handle the result (see below)\r\nif (error === nil && data[0].status === \"OK\") {\r\n    console.log(data); // Access the query results\r\n} else {\r\n    console.error(error); // Access the error response\r\n}\r\n\r\n//Example with variables\r\ntype User = {\r\n  id: string;\r\n  name: string;\r\n}\r\nconst [data, error] = await db.query<User[]>(`SELECT * FROM users WHERE name = $name;`, {name: 'John Doe'});\r\n\r\n//Handle result the same way as before\r\n```\r\n\r\nThe `query` method returns a `QueryResult` which is a tuple:\r\n\r\n`[RequestResult<T>[], ErrorResponse?]`\r\n\r\n*   `RequestResult<T>[]`: An array of `RequestResult` objects. Each object contains the query result (`result`), status (`OK` or `ERR`), and timestamp (`time`).  If the query is successful, `result` will contain the data; otherwise, it will be `null`.\r\n*   `ErrorResponse`: If there is an error, this will contain the error message.  If the query is successful, this will be `null`.\r\n\r\n\r\n### Authentication\r\n\r\nTo authenticate, use the `authenticate` method:\r\n\r\n```typescript\r\ndb.authenticate({\r\n  method: 'Token',\r\n  token: '<your token>'\r\n});\r\n```\r\n\r\nTo invalidate the current authentication, use:\r\n\r\n```typescript\r\ndb.invalidate();\r\n```\r\n\r\n### Error Handling\r\n\r\nThe `query` method returns a tuple. Check the status to determine success or failure.  Error messages are provided in the second element of the tuple.\r\n\r\n## Versioning\r\n\r\nSpecify the SurrealDB version using the `version` option in the constructor (`1.x <=` or `>= 2.x`).  The default is `>= 2.x`.\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}