{"id":18256887,"url":"https://github.com/mediacomem/bookshelf-touch","last_synced_at":"2025-04-08T22:29:00.639Z","repository":{"id":73832299,"uuid":"111111791","full_name":"MediaComem/bookshelf-touch","owner":"MediaComem","description":"Automatically update timestamps on your Bookshelf models when saving","archived":false,"fork":false,"pushed_at":"2017-11-30T08:22:54.000Z","size":190,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-16T07:36:28.121Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/MediaComem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-11-17T14:20:45.000Z","updated_at":"2018-01-27T14:35:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"09f0086a-ab59-4d38-8f65-befe32b896f6","html_url":"https://github.com/MediaComem/bookshelf-touch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fbookshelf-touch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fbookshelf-touch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fbookshelf-touch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fbookshelf-touch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MediaComem","download_url":"https://codeload.github.com/MediaComem/bookshelf-touch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938575,"owners_count":21021553,"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":[],"created_at":"2024-11-05T10:24:01.689Z","updated_at":"2025-04-08T22:29:00.626Z","avatar_url":"https://github.com/MediaComem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bookshelf-touch\n\nThis [Bookshelf.js](http://bookshelfjs.org) plugin automatically updates your timestamps when saving your Bookshelf models.\n\n[![npm version](https://badge.fury.io/js/bookshelf-touch.svg)](https://badge.fury.io/js/bookshelf-touch)\n[![Dependency Status](https://gemnasium.com/badges/github.com/MediaComem/bookshelf-touch.svg)](https://gemnasium.com/github.com/MediaComem/bookshelf-touch)\n[![Build Status](https://travis-ci.org/MediaComem/bookshelf-touch.svg?branch=master)](https://travis-ci.org/MediaComem/bookshelf-touch)\n[![Coverage Status](https://coveralls.io/repos/github/MediaComem/bookshelf-touch/badge.svg?branch=master)](https://coveralls.io/github/MediaComem/bookshelf-touch?branch=master)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Usage](#usage)\n- [Configuration](#configuration)\n  - [Timestamp configuration](#timestamp-configuration)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\nDeveloped at the [Media Engineering Institute](http://mei.heig-vd.ch) ([HEIG-VD](https://heig-vd.ch)).\n\n\n\n## Usage\n\n```js\nconst knex = require('knex')({ ... });\nconst bookshelf = require('bookshelf')(knex);\nconst touch = require('bookshelf-touch');\n\nbookshelf.plugin(touch);\n\nconst MyModel = bookshelf.Model.extend({\n  tableName: 'my_table',\n  // Define which timestamps you want to be automatically updated\n  // (supports \"created_at\" and \"updated_at\" by default, but you\n  // can configure more).\n  timestamps: [ 'created_at', 'updated_at' ]\n});\n\nconst model = new MyModel({\n  name: 'Awesome'\n});\n\n// Both timestamps are automatically set when the model is created.\nmodel.save();\n\n// Only the updated_at timestamp is updated when the model is saved.\nmodel.name = 'Indeed';\nmodel.save();\n\n// You can trigger an update of the timestamps with the touch method\n// (this does not save the model):\nmodel.touch();\n```\n\n\n\n## Configuration\n\nThe `timestamps` property of your model can be:\n\n* `true` to automatically update both `created_at` and `updated_at`.\n\n* A string indicating which of `created_at` or `updated_at` should be updated.\n\n* An array containing either `created_at`, `updated_at` or both to indicate which should be updated.\n\n* An object mapping timestamp columns as keys to timestamp configurations as value. See [Timestamp configuration](#timestamp-configuration) below.\n\n* Do not define it or set it to false to disable the plugin on that model.\n\n### Timestamp configuration\n\nYou may configure the behavior of timestamps (and add timestamps) yourself.\nThis is what the default configuration looks like:\n\n```js\nconst MyModel = bookshelf.Model.extend({\n  tableName: 'my_table',\n  timestamps: {\n    created_at: {}\n    updated_at: {\n      default: record =\u003e record.get('created_at'),\n      update: true\n    }\n  }\n});\n```\n\nA timestamp configuration object has 2 options:\n\n* `default` - A function that takes the record as an argument and should return a default value.\n  This function will be called if the record has no value for that timestamp, or when updating\n  the timestamp. If it returns a falsy value, a new date is created instead. If the default\n  function is not specified (like for `created_at`), a new date is also created as the default\n  value.\n* `update` - Whether to update the timestamp when the record is touched. This defaults to false.\n  As expected, it is not set for `created_at` and set to true for `updated_at` in the default\n  configuration.\n\nYou may define new timestamps by adding them to the configuration.\nUse true and false to enable/disable default timestamps:\n\n```js\nconst MyModel = bookshelf.Model.extend({\n  tableName: 'my_table',\n  timestamps: {\n    created_at: true,\n    updated_at: false,\n    amended_at: {\n      default: record =\u003e new Date(11029388)\n    }\n  }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fbookshelf-touch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediacomem%2Fbookshelf-touch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fbookshelf-touch/lists"}