Skip to content

Instantly share code, notes, and snippets.

@zero5100
Last active August 29, 2015 14:22

Revisions

  1. zero5100 revised this gist Jun 10, 2015. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion postgres date time zone difference
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // Test when ran using the postgresql connector
    // Create a new instance of the model
    loopback:connector:postgresql SQL: INSERT INTO "public"."phone_cdr"("caller_name","caller_number","phone_number_dialed","call_start_date_gmt","call_status") VALUES($1,$2,$3,to_timestamp($4,'yyyy-mm-dd hh24:mi:ss.ms'),$5) RETURNING "id"
    Parameters: ["test","1234567","7654321","2015-01-01T00:00:00.000Z","A"] +465ms
    @@ -155,4 +156,26 @@ loopback:connector:postgresql {
    callDuration: null,
    callStatus: 'A',
    callType: null
    }]
    }]


    // Same test ran with the memory connector instead of the postgresql connector
    // Model that was created
    {
    callerName: 'test',
    callerNumber: '1234567',
    phoneNumberDialed: '7654321',
    callStartDate: Wed Dec 31 2014 18:00:00 GMT-0600 (CST),
    callStatus: 'A',
    id: 1
    }

    // Result from the find
    [ {
    callerName: 'test',
    callerNumber: '1234567',
    phoneNumberDialed: '7654321',
    callStartDate: Wed Dec 31 2014 18:00:00 GMT-0600 (CST),
    callStatus: 'A',
    id: 1
    } ]
  2. zero5100 created this gist Jun 10, 2015.
    158 changes: 158 additions & 0 deletions postgres date time zone difference
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,158 @@
    // Create a new instance of the model
    loopback:connector:postgresql SQL: INSERT INTO "public"."phone_cdr"("caller_name","caller_number","phone_number_dialed","call_start_date_gmt","call_status") VALUES($1,$2,$3,to_timestamp($4,'yyyy-mm-dd hh24:mi:ss.ms'),$5) RETURNING "id"
    Parameters: ["test","1234567","7654321","2015-01-01T00:00:00.000Z","A"] +465ms

    loopback:connector:postgresql {
    "command": "INSERT",
    "rowCount": 1,
    "oid": 0,
    "rows": [{
    "id": 246
    }],
    "fields": [{
    "name": "id",
    "tableID": 16894,
    "columnID": 1,
    "dataTypeID": 23,
    "dataTypeSize": 4,
    "dataTypeModifier": -1,
    "format": "text"
    }],
    "_parsers": [null],
    "rowAsArray": false
    } +4ms

    // Value of returned model
    {
    callerName: 'test',
    callerNumber: '1234567',
    phoneNumberDialed: '7654321',
    callStartDate: Wed Dec 31 2014 18:00:00 GMT-0600 (CST),
    callStatus: 'A',
    id: 246
    }

    // Perform a find by id to get the same model
    loopback:connector:postgresql SQL: SELECT "id","caller_name","caller_number","phone_number_dialed","phone_number_answered","call_start_date_gmt","call_duration","call_status","call_type" FROM "public"."phone_cdr" WHERE "id"=$1 ORDER BY "id"
    Parameters: [246] +3ms

    loopback:connector:postgresql {
    "command": "SELECT",
    "rowCount": 1,
    "oid": null,
    "rows": [{
    "id": 246,
    "caller_name": "test",
    "caller_number": "1234567",
    "phone_number_dialed": "7654321",
    "phone_number_answered": null,
    "call_start_date_gmt": "2015-01-01T06:00:00.000Z",
    "call_duration": null,
    "call_status": "A",
    "call_type": null
    }],
    "fields": [{
    "name": "id",
    "tableID": 16894,
    "columnID": 1,
    "dataTypeID": 23,
    "dataTypeSize": 4,
    "dataTypeModifier": -1,
    "format": "text"
    },
    {
    "name": "caller_name",
    "tableID": 16894,
    "columnID": 2,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 68,
    "format": "text"
    },
    {
    "name": "caller_number",
    "tableID": 16894,
    "columnID": 3,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 19,
    "format": "text"
    },
    {
    "name": "phone_number_dialed",
    "tableID": 16894,
    "columnID": 4,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 19,
    "format": "text"
    },
    {
    "name": "phone_number_answered",
    "tableID": 16894,
    "columnID": 5,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 19,
    "format": "text"
    },
    {
    "name": "call_start_date_gmt",
    "tableID": 16894,
    "columnID": 9,
    "dataTypeID": 1114,
    "dataTypeSize": 8,
    "dataTypeModifier": -1,
    "format": "text"
    },
    {
    "name": "call_duration",
    "tableID": 16894,
    "columnID": 6,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 68,
    "format": "text"
    },
    {
    "name": "call_status",
    "tableID": 16894,
    "columnID": 7,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 14,
    "format": "text"
    },
    {
    "name": "call_type",
    "tableID": 16894,
    "columnID": 8,
    "dataTypeID": 1043,
    "dataTypeSize": -1,
    "dataTypeModifier": 24,
    "format": "text"
    }],
    "_parsers": [null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null],
    "rowAsArray": false
    } +4ms

    // Same object that is returned
    [ {
    id: 246,
    callerName: 'test',
    callerNumber: '1234567',
    phoneNumberDialed: '7654321',
    phoneNumberAnswered: null,
    callStartDate: Thu Jan 01 2015 00:00:00 GMT-0600 (CST),
    callDuration: null,
    callStatus: 'A',
    callType: null
    }]