type-store 0.4.3 → 0.4.4

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.
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "type-store",
3
3
  "description": "type ecosystem",
4
- "version": "0.4.3",
4
+ "version": "0.4.4",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "repository": "codenautas/type-store",
7
7
  "license": "MIT",
8
8
  "main": "type-store.js",
9
9
  "files": [
10
10
  "type-store.js",
11
- "postgres-interval4client.js"
11
+ "postgres-interval4client.js",
12
+ "postgres"
12
13
  ],
13
14
  "dependencies": {
14
15
  "big.js": "^6.2.2",
@@ -0,0 +1,7 @@
1
+ CREATE OR REPLACE FUNCTION time_subtype_diff(x time, y time) RETURNS float8 AS
2
+ 'SELECT EXTRACT(EPOCH FROM (x - y))' LANGUAGE sql STRICT IMMUTABLE;
3
+
4
+ CREATE TYPE time_range AS RANGE (
5
+ subtype = time,
6
+ subtype_diff = time_subtype_diff
7
+ );
package/type-store.js CHANGED
@@ -761,7 +761,7 @@ TypeStore.type.timestamp.prototype.toPlainString=function toPlainString(typedVal
761
761
  return typedValue.toYmdHmsM();
762
762
  };
763
763
 
764
-
764
+ // https://www.postgresql.org/docs/current/sql-createtype.html
765
765
  TypeStore.type.time = function TypeArrayTime(){ TypeBase.apply(this, arguments); };
766
766
  TypeStore.type.time.prototype = Object.create(TypeBase.prototype);
767
767
  TypeStore.type.time.prototype.typeDbPg='time';
@@ -800,6 +800,27 @@ TypeStore.type.time.prototype.toLocalParts=function toLocalParts(typedValue,fPar
800
800
  return fParts(rta, "time");
801
801
  };
802
802
 
803
+ // https://www.postgresql.org/docs/current/sql-createtype.html
804
+ // https://www.postgresql.org/docs/current/rangetypes.html
805
+
806
+ /** @param {{typeName:string, pg_OID?:number, typeDbPg?:string}} param */
807
+ function rangeOf(param){
808
+ var result = function TypeRangeof(){ TypeBase.apply(this, arguments); };
809
+ result.prototype.toPlainString=function toPlainString(typedValue){
810
+ return typedValue;
811
+ };
812
+ result.prototype.fromString=function fromString(textValue){
813
+ return textValue;
814
+ };
815
+ result.prototype.typeDbPg=param.typeDbPg || param.typeName+'_range';
816
+ if (param.pg_OID) result.prototype.pg_OID=param.pg_OID;
817
+ return result
818
+ }
819
+
820
+ TypeStore.type.time_range=rangeOf({typeName:'time'});
821
+ TypeStore.type.tsrange=rangeOf({typeName:'timestamp', typeDbPg:'tsrange', pg_OID:3908});
822
+
823
+
803
824
  // PostgresInterval.prototype.typeStore={type:'interval'};
804
825
 
805
826
  json4all.addType(bestGlobals.TimeInterval,{