{"id":16446298,"url":"https://github.com/lupennat/lupdo-sqlite","last_synced_at":"2025-02-26T10:16:25.679Z","repository":{"id":65137203,"uuid":"581489353","full_name":"Lupennat/lupdo-sqlite","owner":"Lupennat","description":"Lupdo Driver For Sqlite","archived":false,"fork":false,"pushed_at":"2023-12-24T14:06:04.000Z","size":515,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-25T06:21:35.140Z","etag":null,"topics":["abstraction-layer","database","lupdo","nodejs","pdo","sqlite","sqlite3","transactions"],"latest_commit_sha":null,"homepage":"","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/Lupennat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-23T10:39:12.000Z","updated_at":"2023-01-31T22:33:06.000Z","dependencies_parsed_at":"2024-10-11T09:47:08.546Z","dependency_job_id":"3e14a061-b717-44f8-a160-7a8c4e30f06f","html_url":"https://github.com/Lupennat/lupdo-sqlite","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"5ac9b8a4dd0eeb18a1d96d857329bfb6be700626"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lupennat%2Flupdo-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lupennat%2Flupdo-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lupennat%2Flupdo-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lupennat%2Flupdo-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lupennat","download_url":"https://codeload.github.com/Lupennat/lupdo-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240831380,"owners_count":19864718,"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":["abstraction-layer","database","lupdo","nodejs","pdo","sqlite","sqlite3","transactions"],"created_at":"2024-10-11T09:47:05.878Z","updated_at":"2025-02-26T10:16:25.563Z","avatar_url":"https://github.com/Lupennat.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n \u003ca href=\"https://www.npmjs.com/package/lupdo-sqlite\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/npm/v/lupdo-sqlite?color=0476bc\u0026label=\" alt=\"NPM version\"\u003e\n    \u003c/a\u003e\n \u003ca href=\"https://www.npmjs.com/package/lupdo-sqlite\" target=\"__blank\"\u003e\n        \u003cimg alt=\"NPM Downloads\" src=\"https://img.shields.io/npm/dm/lupdo-sqlite?color=3890aa\u0026label=\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://app.codecov.io/github/Lupennat/lupdo-sqlite\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://codecov.io/github/Lupennat/lupdo-sqlite/branch/main/graph/badge.svg?token=19C8E6QTCE\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://snyk.io/test/github/lupennat/lupdo-sqlite\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://snyk.io/test/github/lupennat/lupdo-sqlite/badge.svg\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# Lupdo-sqlite\n\n[Lupdo](https://www.npmjs.com/package/lupdo) Driver For Sqlite.\n[Api](https://lupdo-sqlite.lupennat.com/api/functions/createSqlitePdo.html)\n\n## Supported Databases\n\n- [sqlite/sqlite3](https://www.sqlite.org/index.html)\n\n## Third Party Library\n\nLupdo-sqlite, under the hood, uses stable and performant npm packages:\n\n- [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)\n\n## Usage\n\nBase Example\n\n```js\nconst { createSqlitePdo } = require('lupdo-sqlite');\n// ES6 or Typescrypt\nimport { createSqlitePdo } from 'ludpo-sqlite';\n\nconst pdo = createSqlitePdo({ path: ':memory' }, { min: 2, max: 3 });\nconst run = async () =\u003e {\n    const statement = await pdo.query('SELECT 2');\n    const res = statement.fetchArray().all();\n    console.log(res);\n    await pdo.disconnect();\n};\n\nrun();\n```\n\n## Driver Options\n\n[https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-databasepath-options](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)\n\nnew required option added:\n\n- path: string\n\nnew optional option added\n\n- [wal: boolean](https://www.sqlite.org/wal.html) [default `false`]\n- [synchronous: string](https://sqlite.org/pragma.html#pragma_synchronous) [default `NORMAL` works only when WAL enabled]\n- maxSize: number [default undefined] (MB)\n- onWalError: (err) =\u003e void [default undefined]\n\nWhen WAL is disabled default `journal_mode` will be `delete` for database file and `memory` for memory database.\\\nWhen WAL is enabled and `maxSize` is defined every 5 seconds lupdo-sqlite will check if WAL file is bigger than maxSize, if size is greater than maxSize [wal_checkpoint(TRUNCATE)](https://www.sqlite.org/pragma.html#pragma_wal_checkpoint) is called.\\\nWhen WAL watcher get an error it will call your custom `onWalError` callback with the original error.\\\nSqlite only creates the WAL file when it is needed, which is why it may not exist, here is an example:\n\n```ts\nconst pdo = createSqlitePdo(\n    {\n        path: 'sqlitefile.db',\n        wal: true,\n        maxSize: 100,\n        onWalError: (err: any) =\u003e {\n            if (err.code !== 'ENOENT') {\n                // log the error on your application\n            }\n        }\n    },\n    { min: 2, max: 3 }\n);\n```\n\n## Better Sqlite Overrides\n\nBy default Ludpo-sqlite enable `db.defaultSafeIntegers(true)` and `statement.safeIntegers(true)`.\n[https://github.com/WiseLibs/better-sqlite3/blob/2194095aa1183e9c21d28eafadeac0d4d4d42625/docs/integer.md#getting-bigints-from-the-database](https://github.com/WiseLibs/better-sqlite3/blob/2194095aa1183e9c21d28eafadeac0d4d4d42625/docs/integer.md#getting-bigints-from-the-database)\n\nInternally lupdo-sqlite convert bigint to normal number if precision will be preserved.\n\n\u003e **Note**\n\u003e Custom Aggregate and Function must be adapted as required if using numbers.\n\n## Parameters Binding\n\nLupdo-sqlite ignore type definition of `TypeBinding` parameter.\\\nLupdo-sqlite does not support array of parameters.\n\n## Not Integer Numbers\n\n\u003e **Warning**\n\u003e All non-integer numbers are returned as strings, no precision is guaranteed, you can choose which cast to apply in your application.\n\n## Kill Connection\n\nLupdo-sqlite do not support kill query, if you need to perform very slow queries, you should implement [worker threads](https://github.com/WiseLibs/better-sqlite3/blob/2194095aa1183e9c21d28eafadeac0d4d4d42625/docs/threads.md) by yourself.\n\n\u003e **Note**\n\u003e you can use better-sqlite3 native api, retrieving a raw connection from the pool with `pdo.getRawPoolConnection()`.\n\u003e Do not forget to release rawPoolConnection before stop the job, otherwise the pool will be stuck.\n\n## SqliteDriver Create Function \u0026 Aggregate\n\nSqliteDriver expose two static Method in order to register custom [aggregates](https://sqlite.org/lang_aggfunc.html) and [functions](https://sqlite.org/lang_corefunc.html).\n\nHere You can find more details on [aggregate](https://github.com/WiseLibs/better-sqlite3/blob/HEAD/docs/api.md#aggregatename-options---this) and [functions](https://github.com/WiseLibs/better-sqlite3/blob/HEAD/docs/api.md#functionname-options-function---this) Options.\n\n\u003e **Note**\n\u003e The `SqliteDriver.createFunction(name, options)` differs from the original `better-sqlite3.function(name, [options], function)`, it accepts only a name and a config, config must contains `execute` function.\n\n```ts\nconst { createSqlitePdo, SqliteDriver } = require('lupdo-sqlite');\n// ES6 or Typescrypt\nimport { createSqlitePdo, SqliteDriver } from 'ludpo-sqlite';\n\nSqliteDriver.createAggregate('max_len', {\n    start: 0,\n    step: (context: number, nextValue: string) =\u003e {\n        if (nextValue.length \u003e context) {\n            return nextValue.length;\n        }\n        return context;\n    }\n});\n\nSqliteDriver.createFunction('add2', {\n    execute(a, b) {\n        return a + b;\n    }\n});\n\nconst pdo = createSqlitePdo({ path: './test.db' });\n\nawait pdo.query('SELECT max_len(name) FROM companies;');\nawait pdo.query('SELECT add2(name, gender) FROM users;');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupennat%2Flupdo-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flupennat%2Flupdo-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupennat%2Flupdo-sqlite/lists"}