{"id":17866716,"url":"https://github.com/caspahouzer/ti-jsondb","last_synced_at":"2026-05-07T08:38:09.266Z","repository":{"id":42526589,"uuid":"476335432","full_name":"caspahouzer/ti-jsondb","owner":"caspahouzer","description":"A file based JSON database for TiDev Titanium","archived":false,"fork":false,"pushed_at":"2022-04-17T10:54:54.000Z","size":355,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-08T12:30:24.957Z","etag":null,"topics":["database","helper","json","titanium","titanium-mobile"],"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/caspahouzer.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-03-31T14:12:05.000Z","updated_at":"2023-10-13T15:08:01.000Z","dependencies_parsed_at":"2022-08-28T14:51:39.232Z","dependency_job_id":null,"html_url":"https://github.com/caspahouzer/ti-jsondb","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caspahouzer%2Fti-jsondb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caspahouzer%2Fti-jsondb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caspahouzer%2Fti-jsondb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caspahouzer%2Fti-jsondb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caspahouzer","download_url":"https://codeload.github.com/caspahouzer/ti-jsondb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246899665,"owners_count":20851898,"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":["database","helper","json","titanium","titanium-mobile"],"created_at":"2024-10-28T09:38:30.953Z","updated_at":"2026-05-07T08:38:09.222Z","avatar_url":"https://github.com/caspahouzer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ti.jsondb\n\n## A file based JSON database for TiDev Titanium\n\n### Install node module\n\nFollow these [guidelines](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Best_Practices_and_Recommendations/CommonJS_Modules_in_Titanium.html#commonjs-module-specification-implementation) to know how Titanium handles to work with node modules\n\n    npm install @caspahouzer/ti-jsondb\n\n### Inititate the database as node module\n\n\u003e You can also use that as a normal **/lib** file.\n\nTo do that, copy [ti-jsondb.js](ti-jsondb.js) to `lib/ti-jsondb.js`\n\n\u003e \u0026nbsp;\n ❗️ Warning\n ti-jsondb is made for [Alloy](https://titaniumsdk.com/guide/Alloy_Framework/) and uses [underscore.js](http://underscorejs.org).\n If you want to use it in a classic project, what is **not** the state of art, copy [underscore.js](lib/underscore.js) to `lib/underscore.js`\n \u0026nbsp;\n\n```javascript\n\n// Node module\nimport TiJsonDB from '@caspahouzer/ti-jsondb';\n\n// Alloy \u0026 ES6+\nimport TiJsonDB from 'ti-jsondb';\n\n// Alloy \u0026 ES5\nconst TiJsonDB = require('ti-jsondb');\n\n// Classic \u0026 ES6+\nimport TiJsonDB from 'lib/ti-jsondb';\n```\n\nNow, create a new instance of _TiJsonDB_\n\n```javascript\nconst jsonDatabase = new TiJsonDB({\n    // Show debug information\n    debug: true,\n    // Handle where clause case sensitive\n    caseSensitive: false,\n});\n```\n\n### Working with the database\n\n#### Create / Init table\n\n```javascript\nlet user = jsonDatabase.table('user');\nlet settings = jsonDatabase.table('settings');\n```\n\n#### Truncate table\n\n```javascript\njsonDatabase.table('settings').truncate();\n```\n\n#### Create example settings table with object content\n\n```javascript\n// Insert and return\nsettings = jsonDatabase.table('settings').insert({ id: 'settings', setting1: true, setting2: false, setting3: 'test' });\n\n// get all entries\nsettings = jsonDatabase.table('settings').find('settings');\nconsole.warn('settings', settings);\n```\n\n#### Update object\n\n```javascript\njsonDatabase.table('settings').update({ id: 'settings', setting1: false, setting2: true });\nsettings = jsonDatabase.table('settings').get();\nconsole.warn('settings after update', settings);\n```\n\n#### Push data into table\n\n```javascript\njsonDatabase.table('user').insert({\n    id: '38414679-1a10-42fe-be65-8e6b0b37b234', // remove this line to make a new entry\n    first_name: 'John',\n    last_name: 'Doe',\n    gender: 'Male',\n    email: 'john.doe@example.com',\n});\nconsole.warn('Last inserted id', jsonDatabase.last_insert_id);\n```\n\n#### Delete table completely\n\n```javascript\njsonDatabase.table('test').destroy();\n```\n\n#### Push item for delete action\n\n```javascript\njsonDatabase.table('user').insert({\n    id: 'b8b79689-39a5-4885-80d8-9b8822e061c5',\n    first_name: 'Jane',\n    last_name: 'Doe',\n    gender: 'Female',\n    email: 'jane.doe@example.com',\n});\n```\n\n#### Fetch table\n\n```javascript\njsonDatabase\n    .table('user')\n    .orderBy('name', 'ASC')\n    .get()\n    .forEach((entry) =\u003e {\n        console.warn('entry', entry);\n    });\n```\n\n#### Select fields to return in object\n\n```javascript\njsonDatabase\n    .table('user')\n    .select('first_name, last_name')\n    .orderBy('first_name', 'desc')\n    .limit(10)\n    .get((data) =\u003e {\n        if (data.length \u003e 0) {\n            console.warn('success select', data);\n            return;\n        }\n        console.warn('no entries found');\n    });\n```\n\n#### Delete item by id\n\n```javascript\njsonDatabase.table('user').where('id', '=', 'b8b79689-39a5-4885-80d8-9b8822e061c5').delete();\n```\n\n#### Delete multiple items\n\n```javascript\njsonDatabase.table('user').delete(['b8b79689-39a5-4885-80d8-9b8822e061c5', 'd6c52967-9654-4152-80f8-8fbc5a1e33d6']);\n```\n\n#### fetch data with callback functions\n\n```javascript\njsonDatabase\n    .table('user')\n    .orderBy('first_name', 'rand')\n    .get(\n        (data) =\u003e {\n            if (data.length \u003e 0) {\n                console.warn('success', data[0]);\n                return;\n            }\n            console.warn('no entries found');\n        }),\n        (error) =\u003e {\n            console.warn('error', error);\n        })\n    );\n```\n\n#### Fetch a single item by id\n\n```javascript\nconst singleUser = jsonDatabase.table('user').find('d6c52967-9654-4152-80f8-8fbc5a1e33d6');\nconsole.warn('singleUser', singleUser);\n```\n\n#### Fetch single item by field\n\n```javascript\njsonDatabase.table('user').getSingle(\n    'first_name',\n    'Jane',\n    (data) =\u003e {\n        console.warn('success getSingle', data);\n    },\n    (error) =\u003e {\n        console.warn('error getSingle', error);\n    }\n);\n```\n\n#### Simple where clause\n\n```javascript\njsonDatabase\n    .table('user')\n    .where('first_name', '=', 'Jane')\n    .get((data) =\u003e {\n        console.warn('success simple where', data);\n    });\n```\n\n#### Simple where like clause with limit\n\n```javascript\njsonDatabase\n    .table('user')\n    .where('first_name', 'like', 'Joh')\n    .limit(10)\n    .orderBy('first_name', 'desc')\n    .get((data) =\u003e {\n        console.warn('success simple where with limit', data);\n    });\n```\n\n#### Chained where clause\n\n```javascript\njsonDatabase\n    .table('user')\n    .where('last_name', 'like', 'Min')\n    .where('first_name', '=', 'Etan')\n    .limit(10)\n    .orderBy('first_name', 'desc')\n    .get((data) =\u003e {\n        console.warn('success chained where clause', data);\n    });\n```\n\n#### orWhere clause\n\nThe orWhere clause has be set **after** _where_ clause and can be used like the _where_ function. Give an array to handle multiple wheres which are combined with _AND_\n\n```javascript\njsonDatabase\n    .table('user')\n    .where('first_name', 'like', 'Ja')\n    .orWhere('last_name', '=', 'Doe')\n    .orderBy('first_name')\n    .get((data) =\u003e {\n        console.warn('success where array and chained orWhere', data);\n    });\n```\n\n#### Update multiple entries\n\n```javascript\njsonDatabase.table('user')\n    .where('first_name', 'like', 'John')\n    .limit(10)\n    .update({ first_name: 'Johny' },\n    success = (counter){\n        console.log('Updated '+counter+' entries')\n    });\n```\n\n#### Delete entries\n\n```javascript\njsonDatabase.table('user')\n    .where('first_name', 'like', 'John')\n    .delete(\n    success = (counter){\n        console.log('Deleted '+counter+' entries')\n    });\n```\n\nGet an [overview](./methods.md) to all functions and parameters\n\n---\n\n\u0026copy; 2022 Sebastian Klaus\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaspahouzer%2Fti-jsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaspahouzer%2Fti-jsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaspahouzer%2Fti-jsondb/lists"}