{"id":22550919,"url":"https://github.com/thipages/sqlite-csv","last_synced_at":"2025-04-10T03:21:39.507Z","repository":{"id":265181822,"uuid":"895373763","full_name":"thipages/sqlite-csv","owner":"thipages","description":"Load csv in sqlite with the right types and some stats","archived":false,"fork":false,"pushed_at":"2025-03-20T00:32:14.000Z","size":58,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T00:41:31.655Z","etag":null,"topics":["cli","sqlite","stats","types"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/thipages.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-28T04:57:17.000Z","updated_at":"2025-03-20T00:31:51.000Z","dependencies_parsed_at":"2024-11-28T07:18:33.834Z","dependency_job_id":null,"html_url":"https://github.com/thipages/sqlite-csv","commit_stats":null,"previous_names":["thipages/sqlite-csv"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fsqlite-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fsqlite-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fsqlite-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fsqlite-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thipages","download_url":"https://codeload.github.com/thipages/sqlite-csv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148701,"owners_count":21055637,"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":["cli","sqlite","stats","types"],"created_at":"2024-12-07T17:08:59.928Z","updated_at":"2025-04-10T03:21:39.499Z","avatar_url":"https://github.com/thipages.png","language":"JavaScript","readme":"# sqlite-csv\nLoad csv files in sqlite databases with the right types and some stats via `sqlite3 cli`.\n\nIt requires [sqlite3](https://www.sqlite.org/download.html) \u003e= 3.36.0  (REGEXP support) installed on the OS.\n\n## What it does\n- Loads the csv file into sqlite\n- Defines types (`text`, `real` or `integer`) at the schema level\n  - zero leading integers are considered as `text`\n  - dot is used for identifying  `real` data\n  - precedence order is computed as followed : `text` \u003e `real` \u003e `integer`\n- Replaces empty values by `null` values\n- Defines or create if not specified a primary key\n- Creates a table with basic statistics for each field\n\n## NPX usage\nnpx command will load in `dbname` all csv files present in the folder where npx is run. Tables names match `csv` file names along stats tables suffixed with `_stats`. Delimiter is automatically detected but restricted to\n- the first line of the `csv` file\n- comma and semi-colon\n\n### Options\n- `-fk`: add foreign key(s) with the following syntax `-fk \"referenceTable fkTable(fkField)\"`\n- `-sql` : add a sql post-treatment like `-sql sqlFilePath`\n\n```shell\nnpx @titsoft/sqlite-csv dbname\n```\n\n## ESM usage\nvia `npm i @titsoft/sqlite-csv`\n```javascript\nimport {importCsv} from '@titsoft/sqlite-csv'\nconst stats = await importCsv(dbPath, csvPath, options)\n```\n### Options object\n- `separator`:  csv separator, default `','`\n- `csvTable`: name of the imported csv table, default `'main'`\n- `statsTable`: name of the stats table, default `'main_stats'`,\n- `primaryKey`: name of the primary key, default `id`\n\n### `importCsv` returned value\nreturns an array of object\n- `field`  one of the field\n- `type` 0 | 1 | 2\n- `sType` text | real | integer\n- `distinct` number of distinct values (null not counted)\n- `null`: number of null values\n- `min` min field value\n- `max` max field value\n- `avg` average field value\n- `total` total number of records\n\nNotes\n- `min`, `max` and `avg` are length-based for `text` type\n- `min`, `max`, `avg`, `distinct` computation discards `null` values\n- `type` and `sType` represents the same descriptor\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fsqlite-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthipages%2Fsqlite-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fsqlite-csv/lists"}