New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

objection-timestamp-edgeruntime

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection-timestamp-edgeruntime

Objectionjs plugin to update created_at and updated_at columns tweaked to peer dependency on an edge compat build

  • 1.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

workflow

Objection-timestamps

Automatically modify the created_at and updated_at columns on your models.

v0.x usage

v1.x and v2.x usage

Setup

Basic

The basic setup assumes you have the columns created_at and updated_at in your table.


let Model = require('objection').Model;
let timestampPlugin = require('objection-timestamps').timestampPlugin;

class Post extends timestampPlugin()(Model) {
    static get tableName() {
        return 'user';
    }
    // allow timestamp plugin on this model
    static get timestamp() {
        return true;
    }
}

Post
    .query()
    .insertAndFetch({
        firstName: 'John',
        lastName: 'Doe'
    })
    .then(john => {
        console.log(john.created_at); // ISO-8601 Date format:  YYYY-MM-DDTHH:mm:ss.sssZ
        console.log(john.updated_at); // ISO-8601 Date format:  YYYY-MM-DDTHH:mm:ss.sssZ
    });

Advanced

You can pass in an object to override the default settings


let Model = require('objection').Model;
let timestampPlugin = require('objection-timestamps').timestampPlugin;

let plugin = timestampPlugin({
    createdAt: 'my_created_at', // change createdAt column name
    updatedAt: 'my_updated_at', // change updatedAt column name
    genDate: function() {
        return 'my date format';
    }
});

class Post extends plugin(Model) {
    static get tableName() {
        return 'user';
    }
    // allow timestamp plugin on this model
    static get timestamp() {
        return true;
    }
}

Post
    .query()
    .insertAndFetch({
        firstName: 'John',
        lastName: 'Doe'
    })
    .then(john => {
        console.log(john.my_created_at); // my date format
        console.log(john.my_updated_at); // my date format
    });

If you provide custom values plugin won't override them


let Model = require('objection').Model;
let timestampPlugin = require('objection-timestamps').timestampPlugin;

class Post extends timestampPlugin()(Model) {
    static get tableName() {
        return 'user';
    }
    // allow timestamp plugin on this model
    static get timestamp() {
        return true;
    }
}

Post
    .query()
    .insertAndFetch({
        firstName: 'John',
        lastName: 'Doe',
        created_at: 'Foobar',
        updated_at: 'Foobiz'
    })
    .then(john => {
        console.log(john.created_at); // Foobar
        console.log(john.updated_at); // Foobiz
    });

Keywords

FAQs

Package last updated on 08 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc