{"id":17957542,"url":"https://github.com/itinance/sql-schema-lite","last_synced_at":"2025-04-03T17:32:19.002Z","repository":{"id":57368259,"uuid":"80254528","full_name":"itinance/sql-schema-lite","owner":"itinance","description":"A simple SQL-builder in modern JavaScript especially for SQLite3 ","archived":false,"fork":false,"pushed_at":"2017-01-28T11:23:00.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T11:29:27.079Z","etag":null,"topics":["javascript","orm","react-nat","schema","sql-builder","sql-statement","sqlite-orm","sqlite3"],"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/itinance.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":"2017-01-27T23:24:39.000Z","updated_at":"2021-04-09T08:02:39.000Z","dependencies_parsed_at":"2022-09-05T20:51:18.140Z","dependency_job_id":null,"html_url":"https://github.com/itinance/sql-schema-lite","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/itinance%2Fsql-schema-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Fsql-schema-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Fsql-schema-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Fsql-schema-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itinance","download_url":"https://codeload.github.com/itinance/sql-schema-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247046745,"owners_count":20874714,"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":["javascript","orm","react-nat","schema","sql-builder","sql-statement","sqlite-orm","sqlite3"],"created_at":"2024-10-29T10:55:32.729Z","updated_at":"2025-04-03T17:32:18.970Z","avatar_url":"https://github.com/itinance.png","language":"JavaScript","readme":"# sql-schema-lite\n\n## Motivation:\n\nThis is something like a SQL-Builder primarily in the context of mobile applications or web\napplications using Sqlite3, which is present on mobile devices and in any modern web browser (websql is sqlite3 under the hood).\n\nIt takes concrete schema definitions and supports the developer with building\nspecific SQL-statements like SELECT, UPDATE, INSERT, DELETE.\n(DDL-statements like CREATE TABLE/ALTER TABLE are coming soon)\n\nThe library is supposed to be a loosely coupled SQL builder library\nwithout any bindings to concrete OS-related or database-related implementations, but\ncan be used as a base library around SQL-statement building for those advanced implementations.\nSo feel free to use this in any environment (whether it is server side with NodeJS, client side\non browsers or cross platform mobile applications with Cordova, ReactNative and so on...)\n\nThat means, this library is NOT an ORM-implementation ([Object relational mapper](https://en.wikipedia.org/wiki/Object-relational_mapping)), but it is the\noutsourced part of a ReactNative-specific library [react_native_sqlite_orm](https://github.com/itinance/react_native_sqlite_orm)\non top of [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage/) supporting sqlite3 for both\niOS and Android, that is currently under heavy development and not being published yet (coming very soon).\n\n## Installation:\n\nvia yarn:\n\n```\nyarn add sqlite-schema-lite\n```\n\nvia npm:\n\n```\nnpm install --save sqlite-schema-lite\n```\n\n## Running tests\n\nTests are written with [jest](https://github.com/facebook/jest/). You need to install\nthe [jest-client](https://www.npmjs.com/package/jest-cli) best globally: npm install jest-cli.\n\n```\nyarn install\njest\n```\n\nOr if you're still using npm:\n\n```\nnpm i\njest\n```\n\n\n## Examples:\n\nDefine a schema per JS or JSON:\n\n```javascript\nconst schemaContact = {\n  name: 'contact',\n  defaultVersion: 1,\n\n  // Version 1:\n\n  1: {\n    id: {\n      type: SqliteTypes.INTEGER,\n      autoIncrement: true,\n      primaryKey: true,\n    },\n    first_name: {\n      type: SqliteTypes.TEXT,\n      index: true,\n      nullable: true,\n    },\n    last_name: {\n      type: SqliteTypes.TEXT,\n      index: true,\n      nullable: false,\n    },\n    street: {\n      type: SqliteTypes.TEXT,\n      index: true,\n      nullable: false,\n    },\n    postalcode: {\n      type: SqliteTypes.INTEGER,\n      index: true,\n      nullable: false,\n    },\n    city: {\n      type: SqliteTypes.TEXT,\n      index: true,\n      nullable: false,\n    },\n  }\n}\n```\n\nLet's create SQL-statements for SELECT, INSERT, UPDATE, DELETE automatically:\n\n```javascript\nconst schema = new ModelSchema( schemaContact )\nconst sql = new SqlBuilder(schema)\n\nconst entity = {\n  id: 10,\n  first_name: 'Alfons',\n  last_name: 'Zitterbacke',\n  street: 'Friedenseck 8',\n  postalcode: '15232',\n  city: 'Frankfurt (Oder)'\n}\n\nconsole.log( sql.update(entity) )\n```\n\nupdate() returns a plain object containing the SQL-statement as is with prepared statements\nand the parameter-array containing all parameters. It takes note of primary keys\nand use them as WHERE-statement for a specific record update:\n\n```javascript\n{\n  stmt: 'UPDATE contact SET first_name=?, last_name=?, street=?, postalcode=?, city=? WHERE id=?',\n  params: ['Alfons', 'Zitterbacke', 'Friedenseck 8', '15232', 'Frankfurt (Oder)', 10]\n}\n```\n\n## Contribution:\n\nContributors are welcome! Feel free to submit pull requests or open [discussions](https://github.com/itinance/sql-schema-lite/issues).\n\nIn case of submitting pull requests (highly appreciated) please keep in mind that we are [test driven] (https://github.com/itinance/sql-schema-lite/tree/master/__tests__).\n\n## Author\n\nHagen Hübel, Munich/Starnberg, Germany\n\nFullstacker, currently massive ReactNative developer \u0026 consultant\n\n[LinkedIn](https://www.linkedin.com/in/hagenhuebel)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinance%2Fsql-schema-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitinance%2Fsql-schema-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinance%2Fsql-schema-lite/lists"}