@toxplanet/pegasus-sdk 1.1.21 → 1.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/chemicals.js +14 -14
  2. package/package.json +1 -1
package/lib/chemicals.js CHANGED
@@ -121,7 +121,7 @@ class ChemicalsService {
121
121
  _buildChemicalUpsertSql(chemical) {
122
122
  const upsertSql = [
123
123
  'INSERT INTO chemicals (source_id, chemical_name, chemical_meta, chemical_identifiers, chemical_synonyms, chemical_categories, created_at, updated_at)',
124
- 'VALUES (:source_id, :chemical_name, :chemical_meta::jsonb, :chemical_identifiers::jsonb, :chemical_synonyms::text[], :chemical_categories::text[], :created_at, :updated_at)',
124
+ 'VALUES (:source_id, :chemical_name, :chemical_meta::jsonb, :chemical_identifiers::jsonb, :chemical_synonyms::text[], :chemical_categories::text[], :created_at::timestamp, :updated_at::timestamp)',
125
125
  'ON CONFLICT (source_id) DO UPDATE SET',
126
126
  ' chemical_name = EXCLUDED.chemical_name,',
127
127
  ' chemical_meta = EXCLUDED.chemical_meta,',
@@ -139,8 +139,8 @@ class ChemicalsService {
139
139
  { name: 'chemical_identifiers', value: { stringValue: JSON.stringify(chemical.chemicalIdentifiers ?? {}) }, typeHint: 'JSON' },
140
140
  { name: 'chemical_synonyms', value: { stringValue: this._toPostgresArray(chemical.chemicalSynonyms ?? []) } },
141
141
  { name: 'chemical_categories', value: { stringValue: this._toPostgresArray(chemical.chemicalCategories ?? []) } },
142
- { name: 'created_at', value: { stringValue: this._serializeDate(chemical.createdAt) }, typeHint: 'TIMESTAMP' },
143
- { name: 'updated_at', value: { stringValue: this._serializeDate(chemical.updatedAt) }, typeHint: 'TIMESTAMP' }
142
+ { name: 'created_at', value: { stringValue: this._serializeDate(chemical.createdAt) } },
143
+ { name: 'updated_at', value: { stringValue: this._serializeDate(chemical.updatedAt) } }
144
144
  ];
145
145
 
146
146
  return { sql: upsertSql, parameters };
@@ -327,7 +327,7 @@ class ChemicalsService {
327
327
  await this.connection.ensureConnected();
328
328
 
329
329
  const columns = ['source_id', 'chemical_name', 'chemical_meta', 'chemical_identifiers', 'chemical_synonyms', 'chemical_categories', 'created_at', 'updated_at'];
330
- const values = [':source_id', ':chemical_name', ':chemical_meta::jsonb', ':chemical_identifiers::jsonb', ':chemical_synonyms::text[]', ':chemical_categories::text[]', ':created_at', ':updated_at'];
330
+ const values = [':source_id', ':chemical_name', ':chemical_meta::jsonb', ':chemical_identifiers::jsonb', ':chemical_synonyms::text[]', ':chemical_categories::text[]', ':created_at::timestamp', ':updated_at::timestamp'];
331
331
  const params = [
332
332
  { name: 'source_id', value: { stringValue: chemical.source_id } },
333
333
  { name: 'chemical_name', value: { stringValue: chemical.chemical_name } },
@@ -335,14 +335,14 @@ class ChemicalsService {
335
335
  { name: 'chemical_identifiers', value: { stringValue: JSON.stringify(chemical.chemical_identifiers || {}) }, typeHint: 'JSON' },
336
336
  { name: 'chemical_synonyms', value: { stringValue: this._toPostgresArray(chemical.chemical_synonyms || []) } },
337
337
  { name: 'chemical_categories', value: { stringValue: this._toPostgresArray(chemical.chemical_categories || []) } },
338
- { name: 'created_at', value: { stringValue: this._serializeDate(chemical.created_at || new Date()) }, typeHint: 'TIMESTAMP' },
339
- { name: 'updated_at', value: { stringValue: this._serializeDate(chemical.updated_at || new Date()) }, typeHint: 'TIMESTAMP' }
338
+ { name: 'created_at', value: { stringValue: this._serializeDate(chemical.created_at || new Date()) } },
339
+ { name: 'updated_at', value: { stringValue: this._serializeDate(chemical.updated_at || new Date()) } }
340
340
  ];
341
341
 
342
342
  if (chemical.imported_at) {
343
343
  columns.push('imported_at');
344
- values.push(':imported_at');
345
- params.push({ name: 'imported_at', value: { stringValue: this._serializeDate(chemical.imported_at) }, typeHint: 'TIMESTAMP' });
344
+ values.push(':imported_at::timestamp');
345
+ params.push({ name: 'imported_at', value: { stringValue: this._serializeDate(chemical.imported_at) } });
346
346
  }
347
347
 
348
348
  if (chemical.chemical_id) {
@@ -388,8 +388,8 @@ class ChemicalsService {
388
388
  params.push({ name: 'chemical_categories', value: { stringValue: this._toPostgresArray(updates.chemical_categories) } });
389
389
  }
390
390
 
391
- setClauses.push('updated_at = :updated_at');
392
- params.push({ name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) }, typeHint: 'TIMESTAMP' });
391
+ setClauses.push('updated_at = :updated_at::timestamp');
392
+ params.push({ name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) } });
393
393
 
394
394
  params.push({ name: 'id', value: { stringValue: chemicalId } });
395
395
 
@@ -450,11 +450,11 @@ class ChemicalsService {
450
450
  await this.connection.ensureConnected();
451
451
 
452
452
  const pathArray = propertyPath.split('.');
453
- const sql = 'UPDATE chemicals SET chemical_meta = jsonb_set(chemical_meta, :path::text[], :value::jsonb), updated_at = :updated_at WHERE :collection_name = ANY(chemical_categories) RETURNING *';
453
+ const sql = 'UPDATE chemicals SET chemical_meta = jsonb_set(chemical_meta, :path::text[], :value::jsonb), updated_at = :updated_at::timestamp WHERE :collection_name = ANY(chemical_categories) RETURNING *';
454
454
  const params = [
455
455
  { name: 'path', value: { stringValue: JSON.stringify(pathArray) }, typeHint: 'JSON' },
456
456
  { name: 'value', value: { stringValue: JSON.stringify(newValue) }, typeHint: 'JSON' },
457
- { name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) }, typeHint: 'TIMESTAMP' },
457
+ { name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) } },
458
458
  { name: 'collection_name', value: { stringValue: collectionName } }
459
459
  ];
460
460
 
@@ -492,11 +492,11 @@ class ChemicalsService {
492
492
  }
493
493
 
494
494
  const pathArray = propertyPath.split('.');
495
- const sql = `UPDATE chemicals SET chemical_meta = jsonb_set(COALESCE(chemical_meta, '{}'), :path::text[], :value::jsonb), updated_at = :updated_at WHERE ${whereClause} RETURNING *`;
495
+ const sql = `UPDATE chemicals SET chemical_meta = jsonb_set(COALESCE(chemical_meta, '{}'), :path::text[], :value::jsonb), updated_at = :updated_at::timestamp WHERE ${whereClause} RETURNING *`;
496
496
 
497
497
  params.push({ name: 'path', value: { stringValue: JSON.stringify(pathArray) }, typeHint: 'JSON' });
498
498
  params.push({ name: 'value', value: { stringValue: JSON.stringify(newValue) }, typeHint: 'JSON' });
499
- params.push({ name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) }, typeHint: 'TIMESTAMP' });
499
+ params.push({ name: 'updated_at', value: { stringValue: this._serializeDate(new Date()) } });
500
500
 
501
501
  const result = await this.connection.query(sql, params);
502
502
  const updated = result.rows.map(row => this._mapChemicalRow(row));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toxplanet/pegasus-sdk",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
4
4
  "description": "SDK for migrating chemical data to Pegasus PostgreSQL + OpenSearch architecture with Elasticsearch client compatibility",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",