@sqlanvil/cli 1.0.2 → 1.1.0

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 (3) hide show
  1. package/bundle.js +819 -9
  2. package/package.json +1 -1
  3. package/worker_bundle.js +605 -3
package/bundle.js CHANGED
@@ -29,12 +29,12 @@ var childProcess = require('child_process');
29
29
  var fs = require('fs-extra');
30
30
  var tmp = require('tmp');
31
31
  var util = require('util');
32
+ var pg = require('pg');
33
+ var bigquery = require('@google-cloud/bigquery');
32
34
  var EventEmitter = require('events');
33
35
  var Long = require('long');
34
- var bigquery = require('@google-cloud/bigquery');
35
36
  var promisePoolExecutor = require('promise-pool-executor');
36
37
  var sizeof = require('object-sizeof');
37
- var pg = require('pg');
38
38
  var QueryStream = require('pg-query-stream');
39
39
  var readlineSync = require('readline-sync');
40
40
  var untildify = require('untildify');
@@ -74,10 +74,10 @@ var semver__namespace = /*#__PURE__*/_interopNamespace(semver);
74
74
  var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
75
75
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
76
76
  var tmp__namespace = /*#__PURE__*/_interopNamespace(tmp);
77
+ var pg__namespace = /*#__PURE__*/_interopNamespace(pg);
77
78
  var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
78
79
  var Long__default = /*#__PURE__*/_interopDefaultLegacy(Long);
79
80
  var sizeof__default = /*#__PURE__*/_interopDefaultLegacy(sizeof);
80
- var pg__namespace = /*#__PURE__*/_interopNamespace(pg);
81
81
  var QueryStream__default = /*#__PURE__*/_interopDefaultLegacy(QueryStream);
82
82
  var readlineSync__namespace = /*#__PURE__*/_interopNamespace(readlineSync);
83
83
  var untildify__default = /*#__PURE__*/_interopDefaultLegacy(untildify);
@@ -144,6 +144,7 @@ const sqlanvil = $root.sqlanvil = (() => {
144
144
  * @property {sqlanvil.IExtension|null} [extension] WorkflowSettings extension
145
145
  * @property {boolean|null} [includeTestsInCompiledGraph] WorkflowSettings includeTestsInCompiledGraph
146
146
  * @property {string|null} [warehouse] WorkflowSettings warehouse
147
+ * @property {Object.<string,sqlanvil.IConnectionConfig>|null} [connections] WorkflowSettings connections
147
148
  */
148
149
 
149
150
  /**
@@ -156,6 +157,7 @@ const sqlanvil = $root.sqlanvil = (() => {
156
157
  */
157
158
  function WorkflowSettings(properties) {
158
159
  this.vars = {};
160
+ this.connections = {};
159
161
  if (properties)
160
162
  for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
161
163
  if (properties[keys[i]] != null)
@@ -298,6 +300,14 @@ const sqlanvil = $root.sqlanvil = (() => {
298
300
  */
299
301
  WorkflowSettings.prototype.warehouse = "";
300
302
 
303
+ /**
304
+ * WorkflowSettings connections.
305
+ * @member {Object.<string,sqlanvil.IConnectionConfig>} connections
306
+ * @memberof sqlanvil.WorkflowSettings
307
+ * @instance
308
+ */
309
+ WorkflowSettings.prototype.connections = $util.emptyObject;
310
+
301
311
  /**
302
312
  * Creates a new WorkflowSettings instance using the specified properties.
303
313
  * @function create
@@ -357,6 +367,11 @@ const sqlanvil = $root.sqlanvil = (() => {
357
367
  writer.uint32(/* id 16, wireType 0 =*/128).bool(message.includeTestsInCompiledGraph);
358
368
  if (message.warehouse != null && Object.hasOwnProperty.call(message, "warehouse"))
359
369
  writer.uint32(/* id 17, wireType 2 =*/138).string(message.warehouse);
370
+ if (message.connections != null && Object.hasOwnProperty.call(message, "connections"))
371
+ for (let keys = Object.keys(message.connections), i = 0; i < keys.length; ++i) {
372
+ writer.uint32(/* id 18, wireType 2 =*/146).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]);
373
+ $root.sqlanvil.ConnectionConfig.encode(message.connections[keys[i]], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim().ldelim();
374
+ }
360
375
  return writer;
361
376
  };
362
377
 
@@ -480,6 +495,29 @@ const sqlanvil = $root.sqlanvil = (() => {
480
495
  message.warehouse = reader.string();
481
496
  break;
482
497
  }
498
+ case 18: {
499
+ if (message.connections === $util.emptyObject)
500
+ message.connections = {};
501
+ let end2 = reader.uint32() + reader.pos;
502
+ key = "";
503
+ value = null;
504
+ while (reader.pos < end2) {
505
+ let tag2 = reader.uint32();
506
+ switch (tag2 >>> 3) {
507
+ case 1:
508
+ key = reader.string();
509
+ break;
510
+ case 2:
511
+ value = $root.sqlanvil.ConnectionConfig.decode(reader, reader.uint32());
512
+ break;
513
+ default:
514
+ reader.skipType(tag2 & 7);
515
+ break;
516
+ }
517
+ }
518
+ message.connections[key] = value;
519
+ break;
520
+ }
483
521
  default:
484
522
  reader.skipType(tag & 7);
485
523
  break;
@@ -577,6 +615,16 @@ const sqlanvil = $root.sqlanvil = (() => {
577
615
  if (message.warehouse != null && message.hasOwnProperty("warehouse"))
578
616
  if (!$util.isString(message.warehouse))
579
617
  return "warehouse: string expected";
618
+ if (message.connections != null && message.hasOwnProperty("connections")) {
619
+ if (!$util.isObject(message.connections))
620
+ return "connections: object expected";
621
+ let key = Object.keys(message.connections);
622
+ for (let i = 0; i < key.length; ++i) {
623
+ let error = $root.sqlanvil.ConnectionConfig.verify(message.connections[key[i]]);
624
+ if (error)
625
+ return "connections." + error;
626
+ }
627
+ }
580
628
  return null;
581
629
  };
582
630
 
@@ -640,6 +688,16 @@ const sqlanvil = $root.sqlanvil = (() => {
640
688
  message.includeTestsInCompiledGraph = Boolean(object.includeTestsInCompiledGraph);
641
689
  if (object.warehouse != null)
642
690
  message.warehouse = String(object.warehouse);
691
+ if (object.connections) {
692
+ if (typeof object.connections !== "object")
693
+ throw TypeError(".sqlanvil.WorkflowSettings.connections: object expected");
694
+ message.connections = {};
695
+ for (let keys = Object.keys(object.connections), i = 0; i < keys.length; ++i) {
696
+ if (typeof object.connections[keys[i]] !== "object")
697
+ throw TypeError(".sqlanvil.WorkflowSettings.connections: object expected");
698
+ message.connections[keys[i]] = $root.sqlanvil.ConnectionConfig.fromObject(object.connections[keys[i]]);
699
+ }
700
+ }
643
701
  return message;
644
702
  };
645
703
 
@@ -656,8 +714,10 @@ const sqlanvil = $root.sqlanvil = (() => {
656
714
  if (!options)
657
715
  options = {};
658
716
  let object = {};
659
- if (options.objects || options.defaults)
717
+ if (options.objects || options.defaults) {
660
718
  object.vars = {};
719
+ object.connections = {};
720
+ }
661
721
  if (options.defaults) {
662
722
  object.sqlanvilCoreVersion = "";
663
723
  object.defaultProject = "";
@@ -714,6 +774,11 @@ const sqlanvil = $root.sqlanvil = (() => {
714
774
  object.includeTestsInCompiledGraph = message.includeTestsInCompiledGraph;
715
775
  if (message.warehouse != null && message.hasOwnProperty("warehouse"))
716
776
  object.warehouse = message.warehouse;
777
+ if (message.connections && (keys2 = Object.keys(message.connections)).length) {
778
+ object.connections = {};
779
+ for (let j = 0; j < keys2.length; ++j)
780
+ object.connections[keys2[j]] = $root.sqlanvil.ConnectionConfig.toObject(message.connections[keys2[j]], options);
781
+ }
717
782
  return object;
718
783
  };
719
784
 
@@ -746,6 +811,373 @@ const sqlanvil = $root.sqlanvil = (() => {
746
811
  return WorkflowSettings;
747
812
  })();
748
813
 
814
+ sqlanvil.ConnectionConfig = (function() {
815
+
816
+ /**
817
+ * Properties of a ConnectionConfig.
818
+ * @memberof sqlanvil
819
+ * @interface IConnectionConfig
820
+ * @property {string|null} [platform] ConnectionConfig platform
821
+ * @property {string|null} [project] ConnectionConfig project
822
+ * @property {string|null} [dataset] ConnectionConfig dataset
823
+ * @property {string|null} [saKeyId] ConnectionConfig saKeyId
824
+ * @property {string|null} [host] ConnectionConfig host
825
+ * @property {number|null} [port] ConnectionConfig port
826
+ * @property {string|null} [database] ConnectionConfig database
827
+ * @property {string|null} [defaultSchema] ConnectionConfig defaultSchema
828
+ */
829
+
830
+ /**
831
+ * Constructs a new ConnectionConfig.
832
+ * @memberof sqlanvil
833
+ * @classdesc Represents a ConnectionConfig.
834
+ * @implements IConnectionConfig
835
+ * @constructor
836
+ * @param {sqlanvil.IConnectionConfig=} [properties] Properties to set
837
+ */
838
+ function ConnectionConfig(properties) {
839
+ if (properties)
840
+ for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
841
+ if (properties[keys[i]] != null)
842
+ this[keys[i]] = properties[keys[i]];
843
+ }
844
+
845
+ /**
846
+ * ConnectionConfig platform.
847
+ * @member {string} platform
848
+ * @memberof sqlanvil.ConnectionConfig
849
+ * @instance
850
+ */
851
+ ConnectionConfig.prototype.platform = "";
852
+
853
+ /**
854
+ * ConnectionConfig project.
855
+ * @member {string} project
856
+ * @memberof sqlanvil.ConnectionConfig
857
+ * @instance
858
+ */
859
+ ConnectionConfig.prototype.project = "";
860
+
861
+ /**
862
+ * ConnectionConfig dataset.
863
+ * @member {string} dataset
864
+ * @memberof sqlanvil.ConnectionConfig
865
+ * @instance
866
+ */
867
+ ConnectionConfig.prototype.dataset = "";
868
+
869
+ /**
870
+ * ConnectionConfig saKeyId.
871
+ * @member {string} saKeyId
872
+ * @memberof sqlanvil.ConnectionConfig
873
+ * @instance
874
+ */
875
+ ConnectionConfig.prototype.saKeyId = "";
876
+
877
+ /**
878
+ * ConnectionConfig host.
879
+ * @member {string} host
880
+ * @memberof sqlanvil.ConnectionConfig
881
+ * @instance
882
+ */
883
+ ConnectionConfig.prototype.host = "";
884
+
885
+ /**
886
+ * ConnectionConfig port.
887
+ * @member {number} port
888
+ * @memberof sqlanvil.ConnectionConfig
889
+ * @instance
890
+ */
891
+ ConnectionConfig.prototype.port = 0;
892
+
893
+ /**
894
+ * ConnectionConfig database.
895
+ * @member {string} database
896
+ * @memberof sqlanvil.ConnectionConfig
897
+ * @instance
898
+ */
899
+ ConnectionConfig.prototype.database = "";
900
+
901
+ /**
902
+ * ConnectionConfig defaultSchema.
903
+ * @member {string} defaultSchema
904
+ * @memberof sqlanvil.ConnectionConfig
905
+ * @instance
906
+ */
907
+ ConnectionConfig.prototype.defaultSchema = "";
908
+
909
+ /**
910
+ * Creates a new ConnectionConfig instance using the specified properties.
911
+ * @function create
912
+ * @memberof sqlanvil.ConnectionConfig
913
+ * @static
914
+ * @param {sqlanvil.IConnectionConfig=} [properties] Properties to set
915
+ * @returns {sqlanvil.ConnectionConfig} ConnectionConfig instance
916
+ */
917
+ ConnectionConfig.create = function create(properties) {
918
+ return new ConnectionConfig(properties);
919
+ };
920
+
921
+ /**
922
+ * Encodes the specified ConnectionConfig message. Does not implicitly {@link sqlanvil.ConnectionConfig.verify|verify} messages.
923
+ * @function encode
924
+ * @memberof sqlanvil.ConnectionConfig
925
+ * @static
926
+ * @param {sqlanvil.IConnectionConfig} message ConnectionConfig message or plain object to encode
927
+ * @param {$protobuf.Writer} [writer] Writer to encode to
928
+ * @returns {$protobuf.Writer} Writer
929
+ */
930
+ ConnectionConfig.encode = function encode(message, writer) {
931
+ if (!writer)
932
+ writer = $Writer.create();
933
+ if (message.platform != null && Object.hasOwnProperty.call(message, "platform"))
934
+ writer.uint32(/* id 1, wireType 2 =*/10).string(message.platform);
935
+ if (message.project != null && Object.hasOwnProperty.call(message, "project"))
936
+ writer.uint32(/* id 2, wireType 2 =*/18).string(message.project);
937
+ if (message.dataset != null && Object.hasOwnProperty.call(message, "dataset"))
938
+ writer.uint32(/* id 3, wireType 2 =*/26).string(message.dataset);
939
+ if (message.saKeyId != null && Object.hasOwnProperty.call(message, "saKeyId"))
940
+ writer.uint32(/* id 4, wireType 2 =*/34).string(message.saKeyId);
941
+ if (message.host != null && Object.hasOwnProperty.call(message, "host"))
942
+ writer.uint32(/* id 5, wireType 2 =*/42).string(message.host);
943
+ if (message.port != null && Object.hasOwnProperty.call(message, "port"))
944
+ writer.uint32(/* id 6, wireType 0 =*/48).uint32(message.port);
945
+ if (message.database != null && Object.hasOwnProperty.call(message, "database"))
946
+ writer.uint32(/* id 7, wireType 2 =*/58).string(message.database);
947
+ if (message.defaultSchema != null && Object.hasOwnProperty.call(message, "defaultSchema"))
948
+ writer.uint32(/* id 8, wireType 2 =*/66).string(message.defaultSchema);
949
+ return writer;
950
+ };
951
+
952
+ /**
953
+ * Encodes the specified ConnectionConfig message, length delimited. Does not implicitly {@link sqlanvil.ConnectionConfig.verify|verify} messages.
954
+ * @function encodeDelimited
955
+ * @memberof sqlanvil.ConnectionConfig
956
+ * @static
957
+ * @param {sqlanvil.IConnectionConfig} message ConnectionConfig message or plain object to encode
958
+ * @param {$protobuf.Writer} [writer] Writer to encode to
959
+ * @returns {$protobuf.Writer} Writer
960
+ */
961
+ ConnectionConfig.encodeDelimited = function encodeDelimited(message, writer) {
962
+ return this.encode(message, writer).ldelim();
963
+ };
964
+
965
+ /**
966
+ * Decodes a ConnectionConfig message from the specified reader or buffer.
967
+ * @function decode
968
+ * @memberof sqlanvil.ConnectionConfig
969
+ * @static
970
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
971
+ * @param {number} [length] Message length if known beforehand
972
+ * @returns {sqlanvil.ConnectionConfig} ConnectionConfig
973
+ * @throws {Error} If the payload is not a reader or valid buffer
974
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
975
+ */
976
+ ConnectionConfig.decode = function decode(reader, length, error) {
977
+ if (!(reader instanceof $Reader))
978
+ reader = $Reader.create(reader);
979
+ let end = length === undefined ? reader.len : reader.pos + length, message = new $root.sqlanvil.ConnectionConfig();
980
+ while (reader.pos < end) {
981
+ let tag = reader.uint32();
982
+ if (tag === error)
983
+ break;
984
+ switch (tag >>> 3) {
985
+ case 1: {
986
+ message.platform = reader.string();
987
+ break;
988
+ }
989
+ case 2: {
990
+ message.project = reader.string();
991
+ break;
992
+ }
993
+ case 3: {
994
+ message.dataset = reader.string();
995
+ break;
996
+ }
997
+ case 4: {
998
+ message.saKeyId = reader.string();
999
+ break;
1000
+ }
1001
+ case 5: {
1002
+ message.host = reader.string();
1003
+ break;
1004
+ }
1005
+ case 6: {
1006
+ message.port = reader.uint32();
1007
+ break;
1008
+ }
1009
+ case 7: {
1010
+ message.database = reader.string();
1011
+ break;
1012
+ }
1013
+ case 8: {
1014
+ message.defaultSchema = reader.string();
1015
+ break;
1016
+ }
1017
+ default:
1018
+ reader.skipType(tag & 7);
1019
+ break;
1020
+ }
1021
+ }
1022
+ return message;
1023
+ };
1024
+
1025
+ /**
1026
+ * Decodes a ConnectionConfig message from the specified reader or buffer, length delimited.
1027
+ * @function decodeDelimited
1028
+ * @memberof sqlanvil.ConnectionConfig
1029
+ * @static
1030
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1031
+ * @returns {sqlanvil.ConnectionConfig} ConnectionConfig
1032
+ * @throws {Error} If the payload is not a reader or valid buffer
1033
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1034
+ */
1035
+ ConnectionConfig.decodeDelimited = function decodeDelimited(reader) {
1036
+ if (!(reader instanceof $Reader))
1037
+ reader = new $Reader(reader);
1038
+ return this.decode(reader, reader.uint32());
1039
+ };
1040
+
1041
+ /**
1042
+ * Verifies a ConnectionConfig message.
1043
+ * @function verify
1044
+ * @memberof sqlanvil.ConnectionConfig
1045
+ * @static
1046
+ * @param {Object.<string,*>} message Plain object to verify
1047
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1048
+ */
1049
+ ConnectionConfig.verify = function verify(message) {
1050
+ if (typeof message !== "object" || message === null)
1051
+ return "object expected";
1052
+ if (message.platform != null && message.hasOwnProperty("platform"))
1053
+ if (!$util.isString(message.platform))
1054
+ return "platform: string expected";
1055
+ if (message.project != null && message.hasOwnProperty("project"))
1056
+ if (!$util.isString(message.project))
1057
+ return "project: string expected";
1058
+ if (message.dataset != null && message.hasOwnProperty("dataset"))
1059
+ if (!$util.isString(message.dataset))
1060
+ return "dataset: string expected";
1061
+ if (message.saKeyId != null && message.hasOwnProperty("saKeyId"))
1062
+ if (!$util.isString(message.saKeyId))
1063
+ return "saKeyId: string expected";
1064
+ if (message.host != null && message.hasOwnProperty("host"))
1065
+ if (!$util.isString(message.host))
1066
+ return "host: string expected";
1067
+ if (message.port != null && message.hasOwnProperty("port"))
1068
+ if (!$util.isInteger(message.port))
1069
+ return "port: integer expected";
1070
+ if (message.database != null && message.hasOwnProperty("database"))
1071
+ if (!$util.isString(message.database))
1072
+ return "database: string expected";
1073
+ if (message.defaultSchema != null && message.hasOwnProperty("defaultSchema"))
1074
+ if (!$util.isString(message.defaultSchema))
1075
+ return "defaultSchema: string expected";
1076
+ return null;
1077
+ };
1078
+
1079
+ /**
1080
+ * Creates a ConnectionConfig message from a plain object. Also converts values to their respective internal types.
1081
+ * @function fromObject
1082
+ * @memberof sqlanvil.ConnectionConfig
1083
+ * @static
1084
+ * @param {Object.<string,*>} object Plain object
1085
+ * @returns {sqlanvil.ConnectionConfig} ConnectionConfig
1086
+ */
1087
+ ConnectionConfig.fromObject = function fromObject(object) {
1088
+ if (object instanceof $root.sqlanvil.ConnectionConfig)
1089
+ return object;
1090
+ let message = new $root.sqlanvil.ConnectionConfig();
1091
+ if (object.platform != null)
1092
+ message.platform = String(object.platform);
1093
+ if (object.project != null)
1094
+ message.project = String(object.project);
1095
+ if (object.dataset != null)
1096
+ message.dataset = String(object.dataset);
1097
+ if (object.saKeyId != null)
1098
+ message.saKeyId = String(object.saKeyId);
1099
+ if (object.host != null)
1100
+ message.host = String(object.host);
1101
+ if (object.port != null)
1102
+ message.port = object.port >>> 0;
1103
+ if (object.database != null)
1104
+ message.database = String(object.database);
1105
+ if (object.defaultSchema != null)
1106
+ message.defaultSchema = String(object.defaultSchema);
1107
+ return message;
1108
+ };
1109
+
1110
+ /**
1111
+ * Creates a plain object from a ConnectionConfig message. Also converts values to other types if specified.
1112
+ * @function toObject
1113
+ * @memberof sqlanvil.ConnectionConfig
1114
+ * @static
1115
+ * @param {sqlanvil.ConnectionConfig} message ConnectionConfig
1116
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1117
+ * @returns {Object.<string,*>} Plain object
1118
+ */
1119
+ ConnectionConfig.toObject = function toObject(message, options) {
1120
+ if (!options)
1121
+ options = {};
1122
+ let object = {};
1123
+ if (options.defaults) {
1124
+ object.platform = "";
1125
+ object.project = "";
1126
+ object.dataset = "";
1127
+ object.saKeyId = "";
1128
+ object.host = "";
1129
+ object.port = 0;
1130
+ object.database = "";
1131
+ object.defaultSchema = "";
1132
+ }
1133
+ if (message.platform != null && message.hasOwnProperty("platform"))
1134
+ object.platform = message.platform;
1135
+ if (message.project != null && message.hasOwnProperty("project"))
1136
+ object.project = message.project;
1137
+ if (message.dataset != null && message.hasOwnProperty("dataset"))
1138
+ object.dataset = message.dataset;
1139
+ if (message.saKeyId != null && message.hasOwnProperty("saKeyId"))
1140
+ object.saKeyId = message.saKeyId;
1141
+ if (message.host != null && message.hasOwnProperty("host"))
1142
+ object.host = message.host;
1143
+ if (message.port != null && message.hasOwnProperty("port"))
1144
+ object.port = message.port;
1145
+ if (message.database != null && message.hasOwnProperty("database"))
1146
+ object.database = message.database;
1147
+ if (message.defaultSchema != null && message.hasOwnProperty("defaultSchema"))
1148
+ object.defaultSchema = message.defaultSchema;
1149
+ return object;
1150
+ };
1151
+
1152
+ /**
1153
+ * Converts this ConnectionConfig to JSON.
1154
+ * @function toJSON
1155
+ * @memberof sqlanvil.ConnectionConfig
1156
+ * @instance
1157
+ * @returns {Object.<string,*>} JSON object
1158
+ */
1159
+ ConnectionConfig.prototype.toJSON = function toJSON() {
1160
+ return this.constructor.toObject(this, $protobuf__namespace.util.toJSONOptions);
1161
+ };
1162
+
1163
+ /**
1164
+ * Gets the default type url for ConnectionConfig
1165
+ * @function getTypeUrl
1166
+ * @memberof sqlanvil.ConnectionConfig
1167
+ * @static
1168
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1169
+ * @returns {string} The default type url
1170
+ */
1171
+ ConnectionConfig.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1172
+ if (typeUrlPrefix === undefined) {
1173
+ typeUrlPrefix = "type.googleapis.com";
1174
+ }
1175
+ return typeUrlPrefix + "/sqlanvil.ConnectionConfig";
1176
+ };
1177
+
1178
+ return ConnectionConfig;
1179
+ })();
1180
+
749
1181
  sqlanvil.DefaultIcebergConfig = (function() {
750
1182
 
751
1183
  /**
@@ -7579,6 +8011,8 @@ const sqlanvil = $root.sqlanvil = (() => {
7579
8011
  * @property {Array.<sqlanvil.ActionConfig.IColumnDescriptor>|null} [columns] DeclarationConfig columns
7580
8012
  * @property {string|null} [filename] DeclarationConfig filename
7581
8013
  * @property {Array.<string>|null} [tags] DeclarationConfig tags
8014
+ * @property {string|null} [connection] DeclarationConfig connection
8015
+ * @property {Object.<string,string>|null} [columnTypes] DeclarationConfig columnTypes
7582
8016
  */
7583
8017
 
7584
8018
  /**
@@ -7592,6 +8026,7 @@ const sqlanvil = $root.sqlanvil = (() => {
7592
8026
  function DeclarationConfig(properties) {
7593
8027
  this.columns = [];
7594
8028
  this.tags = [];
8029
+ this.columnTypes = {};
7595
8030
  if (properties)
7596
8031
  for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
7597
8032
  if (properties[keys[i]] != null)
@@ -7654,6 +8089,22 @@ const sqlanvil = $root.sqlanvil = (() => {
7654
8089
  */
7655
8090
  DeclarationConfig.prototype.tags = $util.emptyArray;
7656
8091
 
8092
+ /**
8093
+ * DeclarationConfig connection.
8094
+ * @member {string} connection
8095
+ * @memberof sqlanvil.ActionConfig.DeclarationConfig
8096
+ * @instance
8097
+ */
8098
+ DeclarationConfig.prototype.connection = "";
8099
+
8100
+ /**
8101
+ * DeclarationConfig columnTypes.
8102
+ * @member {Object.<string,string>} columnTypes
8103
+ * @memberof sqlanvil.ActionConfig.DeclarationConfig
8104
+ * @instance
8105
+ */
8106
+ DeclarationConfig.prototype.columnTypes = $util.emptyObject;
8107
+
7657
8108
  /**
7658
8109
  * Creates a new DeclarationConfig instance using the specified properties.
7659
8110
  * @function create
@@ -7694,6 +8145,11 @@ const sqlanvil = $root.sqlanvil = (() => {
7694
8145
  if (message.tags != null && message.tags.length)
7695
8146
  for (let i = 0; i < message.tags.length; ++i)
7696
8147
  writer.uint32(/* id 7, wireType 2 =*/58).string(message.tags[i]);
8148
+ if (message.connection != null && Object.hasOwnProperty.call(message, "connection"))
8149
+ writer.uint32(/* id 8, wireType 2 =*/66).string(message.connection);
8150
+ if (message.columnTypes != null && Object.hasOwnProperty.call(message, "columnTypes"))
8151
+ for (let keys = Object.keys(message.columnTypes), i = 0; i < keys.length; ++i)
8152
+ writer.uint32(/* id 9, wireType 2 =*/74).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.columnTypes[keys[i]]).ldelim();
7697
8153
  return writer;
7698
8154
  };
7699
8155
 
@@ -7724,7 +8180,7 @@ const sqlanvil = $root.sqlanvil = (() => {
7724
8180
  DeclarationConfig.decode = function decode(reader, length, error) {
7725
8181
  if (!(reader instanceof $Reader))
7726
8182
  reader = $Reader.create(reader);
7727
- let end = length === undefined ? reader.len : reader.pos + length, message = new $root.sqlanvil.ActionConfig.DeclarationConfig();
8183
+ let end = length === undefined ? reader.len : reader.pos + length, message = new $root.sqlanvil.ActionConfig.DeclarationConfig(), key, value;
7728
8184
  while (reader.pos < end) {
7729
8185
  let tag = reader.uint32();
7730
8186
  if (tag === error)
@@ -7762,6 +8218,33 @@ const sqlanvil = $root.sqlanvil = (() => {
7762
8218
  message.tags.push(reader.string());
7763
8219
  break;
7764
8220
  }
8221
+ case 8: {
8222
+ message.connection = reader.string();
8223
+ break;
8224
+ }
8225
+ case 9: {
8226
+ if (message.columnTypes === $util.emptyObject)
8227
+ message.columnTypes = {};
8228
+ let end2 = reader.uint32() + reader.pos;
8229
+ key = "";
8230
+ value = "";
8231
+ while (reader.pos < end2) {
8232
+ let tag2 = reader.uint32();
8233
+ switch (tag2 >>> 3) {
8234
+ case 1:
8235
+ key = reader.string();
8236
+ break;
8237
+ case 2:
8238
+ value = reader.string();
8239
+ break;
8240
+ default:
8241
+ reader.skipType(tag2 & 7);
8242
+ break;
8243
+ }
8244
+ }
8245
+ message.columnTypes[key] = value;
8246
+ break;
8247
+ }
7765
8248
  default:
7766
8249
  reader.skipType(tag & 7);
7767
8250
  break;
@@ -7828,6 +8311,17 @@ const sqlanvil = $root.sqlanvil = (() => {
7828
8311
  if (!$util.isString(message.tags[i]))
7829
8312
  return "tags: string[] expected";
7830
8313
  }
8314
+ if (message.connection != null && message.hasOwnProperty("connection"))
8315
+ if (!$util.isString(message.connection))
8316
+ return "connection: string expected";
8317
+ if (message.columnTypes != null && message.hasOwnProperty("columnTypes")) {
8318
+ if (!$util.isObject(message.columnTypes))
8319
+ return "columnTypes: object expected";
8320
+ let key = Object.keys(message.columnTypes);
8321
+ for (let i = 0; i < key.length; ++i)
8322
+ if (!$util.isString(message.columnTypes[key[i]]))
8323
+ return "columnTypes: string{k:string} expected";
8324
+ }
7831
8325
  return null;
7832
8326
  };
7833
8327
 
@@ -7870,6 +8364,15 @@ const sqlanvil = $root.sqlanvil = (() => {
7870
8364
  for (let i = 0; i < object.tags.length; ++i)
7871
8365
  message.tags[i] = String(object.tags[i]);
7872
8366
  }
8367
+ if (object.connection != null)
8368
+ message.connection = String(object.connection);
8369
+ if (object.columnTypes) {
8370
+ if (typeof object.columnTypes !== "object")
8371
+ throw TypeError(".sqlanvil.ActionConfig.DeclarationConfig.columnTypes: object expected");
8372
+ message.columnTypes = {};
8373
+ for (let keys = Object.keys(object.columnTypes), i = 0; i < keys.length; ++i)
8374
+ message.columnTypes[keys[i]] = String(object.columnTypes[keys[i]]);
8375
+ }
7873
8376
  return message;
7874
8377
  };
7875
8378
 
@@ -7890,12 +8393,15 @@ const sqlanvil = $root.sqlanvil = (() => {
7890
8393
  object.columns = [];
7891
8394
  object.tags = [];
7892
8395
  }
8396
+ if (options.objects || options.defaults)
8397
+ object.columnTypes = {};
7893
8398
  if (options.defaults) {
7894
8399
  object.name = "";
7895
8400
  object.dataset = "";
7896
8401
  object.project = "";
7897
8402
  object.description = "";
7898
8403
  object.filename = "";
8404
+ object.connection = "";
7899
8405
  }
7900
8406
  if (message.name != null && message.hasOwnProperty("name"))
7901
8407
  object.name = message.name;
@@ -7917,6 +8423,14 @@ const sqlanvil = $root.sqlanvil = (() => {
7917
8423
  for (let j = 0; j < message.tags.length; ++j)
7918
8424
  object.tags[j] = message.tags[j];
7919
8425
  }
8426
+ if (message.connection != null && message.hasOwnProperty("connection"))
8427
+ object.connection = message.connection;
8428
+ let keys2;
8429
+ if (message.columnTypes && (keys2 = Object.keys(message.columnTypes)).length) {
8430
+ object.columnTypes = {};
8431
+ for (let j = 0; j < keys2.length; ++j)
8432
+ object.columnTypes[keys2[j]] = message.columnTypes[keys2[j]];
8433
+ }
7920
8434
  return object;
7921
8435
  };
7922
8436
 
@@ -15055,6 +15569,8 @@ const sqlanvil = $root.sqlanvil = (() => {
15055
15569
  * @property {boolean|null} [disableAssertions] ProjectConfig disableAssertions
15056
15570
  * @property {string|null} [defaultReservation] ProjectConfig defaultReservation
15057
15571
  * @property {boolean|null} [includeTestsInCompiledGraph] ProjectConfig includeTestsInCompiledGraph
15572
+ * @property {Object.<string,sqlanvil.IConnectionConfig>|null} [connections] ProjectConfig connections
15573
+ * @property {string|null} [warehouseConnection] ProjectConfig warehouseConnection
15058
15574
  */
15059
15575
 
15060
15576
  /**
@@ -15067,6 +15583,7 @@ const sqlanvil = $root.sqlanvil = (() => {
15067
15583
  */
15068
15584
  function ProjectConfig(properties) {
15069
15585
  this.vars = {};
15586
+ this.connections = {};
15070
15587
  if (properties)
15071
15588
  for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
15072
15589
  if (properties[keys[i]] != null)
@@ -15193,6 +15710,22 @@ const sqlanvil = $root.sqlanvil = (() => {
15193
15710
  */
15194
15711
  ProjectConfig.prototype.includeTestsInCompiledGraph = false;
15195
15712
 
15713
+ /**
15714
+ * ProjectConfig connections.
15715
+ * @member {Object.<string,sqlanvil.IConnectionConfig>} connections
15716
+ * @memberof sqlanvil.ProjectConfig
15717
+ * @instance
15718
+ */
15719
+ ProjectConfig.prototype.connections = $util.emptyObject;
15720
+
15721
+ /**
15722
+ * ProjectConfig warehouseConnection.
15723
+ * @member {string} warehouseConnection
15724
+ * @memberof sqlanvil.ProjectConfig
15725
+ * @instance
15726
+ */
15727
+ ProjectConfig.prototype.warehouseConnection = "";
15728
+
15196
15729
  /**
15197
15730
  * Creates a new ProjectConfig instance using the specified properties.
15198
15731
  * @function create
@@ -15248,6 +15781,13 @@ const sqlanvil = $root.sqlanvil = (() => {
15248
15781
  writer.uint32(/* id 21, wireType 2 =*/170).string(message.defaultReservation);
15249
15782
  if (message.includeTestsInCompiledGraph != null && Object.hasOwnProperty.call(message, "includeTestsInCompiledGraph"))
15250
15783
  writer.uint32(/* id 22, wireType 0 =*/176).bool(message.includeTestsInCompiledGraph);
15784
+ if (message.connections != null && Object.hasOwnProperty.call(message, "connections"))
15785
+ for (let keys = Object.keys(message.connections), i = 0; i < keys.length; ++i) {
15786
+ writer.uint32(/* id 23, wireType 2 =*/186).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]);
15787
+ $root.sqlanvil.ConnectionConfig.encode(message.connections[keys[i]], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim().ldelim();
15788
+ }
15789
+ if (message.warehouseConnection != null && Object.hasOwnProperty.call(message, "warehouseConnection"))
15790
+ writer.uint32(/* id 24, wireType 2 =*/194).string(message.warehouseConnection);
15251
15791
  return writer;
15252
15792
  };
15253
15793
 
@@ -15363,6 +15903,33 @@ const sqlanvil = $root.sqlanvil = (() => {
15363
15903
  message.includeTestsInCompiledGraph = reader.bool();
15364
15904
  break;
15365
15905
  }
15906
+ case 23: {
15907
+ if (message.connections === $util.emptyObject)
15908
+ message.connections = {};
15909
+ let end2 = reader.uint32() + reader.pos;
15910
+ key = "";
15911
+ value = null;
15912
+ while (reader.pos < end2) {
15913
+ let tag2 = reader.uint32();
15914
+ switch (tag2 >>> 3) {
15915
+ case 1:
15916
+ key = reader.string();
15917
+ break;
15918
+ case 2:
15919
+ value = $root.sqlanvil.ConnectionConfig.decode(reader, reader.uint32());
15920
+ break;
15921
+ default:
15922
+ reader.skipType(tag2 & 7);
15923
+ break;
15924
+ }
15925
+ }
15926
+ message.connections[key] = value;
15927
+ break;
15928
+ }
15929
+ case 24: {
15930
+ message.warehouseConnection = reader.string();
15931
+ break;
15932
+ }
15366
15933
  default:
15367
15934
  reader.skipType(tag & 7);
15368
15935
  break;
@@ -15452,6 +16019,19 @@ const sqlanvil = $root.sqlanvil = (() => {
15452
16019
  if (message.includeTestsInCompiledGraph != null && message.hasOwnProperty("includeTestsInCompiledGraph"))
15453
16020
  if (typeof message.includeTestsInCompiledGraph !== "boolean")
15454
16021
  return "includeTestsInCompiledGraph: boolean expected";
16022
+ if (message.connections != null && message.hasOwnProperty("connections")) {
16023
+ if (!$util.isObject(message.connections))
16024
+ return "connections: object expected";
16025
+ let key = Object.keys(message.connections);
16026
+ for (let i = 0; i < key.length; ++i) {
16027
+ let error = $root.sqlanvil.ConnectionConfig.verify(message.connections[key[i]]);
16028
+ if (error)
16029
+ return "connections." + error;
16030
+ }
16031
+ }
16032
+ if (message.warehouseConnection != null && message.hasOwnProperty("warehouseConnection"))
16033
+ if (!$util.isString(message.warehouseConnection))
16034
+ return "warehouseConnection: string expected";
15455
16035
  return null;
15456
16036
  };
15457
16037
 
@@ -15508,6 +16088,18 @@ const sqlanvil = $root.sqlanvil = (() => {
15508
16088
  message.defaultReservation = String(object.defaultReservation);
15509
16089
  if (object.includeTestsInCompiledGraph != null)
15510
16090
  message.includeTestsInCompiledGraph = Boolean(object.includeTestsInCompiledGraph);
16091
+ if (object.connections) {
16092
+ if (typeof object.connections !== "object")
16093
+ throw TypeError(".sqlanvil.ProjectConfig.connections: object expected");
16094
+ message.connections = {};
16095
+ for (let keys = Object.keys(object.connections), i = 0; i < keys.length; ++i) {
16096
+ if (typeof object.connections[keys[i]] !== "object")
16097
+ throw TypeError(".sqlanvil.ProjectConfig.connections: object expected");
16098
+ message.connections[keys[i]] = $root.sqlanvil.ConnectionConfig.fromObject(object.connections[keys[i]]);
16099
+ }
16100
+ }
16101
+ if (object.warehouseConnection != null)
16102
+ message.warehouseConnection = String(object.warehouseConnection);
15511
16103
  return message;
15512
16104
  };
15513
16105
 
@@ -15524,8 +16116,10 @@ const sqlanvil = $root.sqlanvil = (() => {
15524
16116
  if (!options)
15525
16117
  options = {};
15526
16118
  let object = {};
15527
- if (options.objects || options.defaults)
16119
+ if (options.objects || options.defaults) {
15528
16120
  object.vars = {};
16121
+ object.connections = {};
16122
+ }
15529
16123
  if (options.defaults) {
15530
16124
  object.warehouse = "";
15531
16125
  object.defaultSchema = "";
@@ -15541,6 +16135,7 @@ const sqlanvil = $root.sqlanvil = (() => {
15541
16135
  object.disableAssertions = false;
15542
16136
  object.defaultReservation = "";
15543
16137
  object.includeTestsInCompiledGraph = false;
16138
+ object.warehouseConnection = "";
15544
16139
  }
15545
16140
  if (message.warehouse != null && message.hasOwnProperty("warehouse"))
15546
16141
  object.warehouse = message.warehouse;
@@ -15576,6 +16171,13 @@ const sqlanvil = $root.sqlanvil = (() => {
15576
16171
  object.defaultReservation = message.defaultReservation;
15577
16172
  if (message.includeTestsInCompiledGraph != null && message.hasOwnProperty("includeTestsInCompiledGraph"))
15578
16173
  object.includeTestsInCompiledGraph = message.includeTestsInCompiledGraph;
16174
+ if (message.connections && (keys2 = Object.keys(message.connections)).length) {
16175
+ object.connections = {};
16176
+ for (let j = 0; j < keys2.length; ++j)
16177
+ object.connections[keys2[j]] = $root.sqlanvil.ConnectionConfig.toObject(message.connections[keys2[j]], options);
16178
+ }
16179
+ if (message.warehouseConnection != null && message.hasOwnProperty("warehouseConnection"))
16180
+ object.warehouseConnection = message.warehouseConnection;
15579
16181
  return object;
15580
16182
  };
15581
16183
 
@@ -38006,7 +38608,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
38006
38608
  .filter(validationQuery => !!validationQuery.query);
38007
38609
  }
38008
38610
 
38009
- const version = "1.0.2";
38611
+ const version = "1.1.0";
38010
38612
  const dataformVersion = "3.0.59";
38011
38613
 
38012
38614
  async function build(compiledGraph, runConfig, dbadapter) {
@@ -38329,7 +38931,7 @@ async function init(projectDir, projectConfig) {
38329
38931
  fs__namespace$1.mkdirSync(projectDir);
38330
38932
  dirsCreated.push(projectDir);
38331
38933
  }
38332
- const warehouse = projectConfig.warehouse || "bigquery";
38934
+ const warehouse = projectConfig.warehouse || "supabase";
38333
38935
  const isBigQuery = warehouse === "bigquery";
38334
38936
  const workflowSettings = {
38335
38937
  sqlanvilCoreVersion: version
@@ -38409,6 +39011,178 @@ async function init(projectDir, projectConfig) {
38409
39011
  };
38410
39012
  }
38411
39013
 
39014
+ const BIGQUERY_TYPE_MAP = {
39015
+ STRING: "text",
39016
+ BYTES: "bytea",
39017
+ INT64: "bigint",
39018
+ INTEGER: "bigint",
39019
+ FLOAT64: "float8",
39020
+ FLOAT: "float8",
39021
+ NUMERIC: "numeric",
39022
+ BIGNUMERIC: "numeric",
39023
+ BOOL: "boolean",
39024
+ BOOLEAN: "boolean",
39025
+ TIMESTAMP: "timestamptz",
39026
+ DATETIME: "timestamp",
39027
+ DATE: "date",
39028
+ TIME: "time",
39029
+ JSON: "jsonb",
39030
+ GEOGRAPHY: "text"
39031
+ };
39032
+ function mapBigQueryType(bqType) {
39033
+ const key = bqType.trim().toUpperCase();
39034
+ const mapped = BIGQUERY_TYPE_MAP[key];
39035
+ if (!mapped) {
39036
+ throw new Error(`Unmapped BigQuery type "${bqType}". Add it to BIGQUERY_TYPE_MAP or set the column type by hand.`);
39037
+ }
39038
+ return mapped;
39039
+ }
39040
+ function mapPostgresType(pgType) {
39041
+ return pgType.trim().toLowerCase();
39042
+ }
39043
+ function keyToken(name) {
39044
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name) ? name : `"${name}"`;
39045
+ }
39046
+ function quote(value) {
39047
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
39048
+ }
39049
+ function renderDeclarationSqlx(opts) {
39050
+ const lines = [];
39051
+ lines.push("config {");
39052
+ lines.push(` type: "declaration",`);
39053
+ lines.push(` connection: ${quote(opts.connection)},`);
39054
+ if (opts.schema) {
39055
+ lines.push(` schema: ${quote(opts.schema)},`);
39056
+ }
39057
+ lines.push(` name: ${quote(opts.name)},`);
39058
+ const typeLines = opts.columns.map(function (c) { return ` ${keyToken(c.name)}: ${quote(c.type)}`; });
39059
+ const described = opts.columns.filter(function (c) { return !!c.description; });
39060
+ lines.push(` columnTypes: {`);
39061
+ lines.push(typeLines.join(",\n"));
39062
+ lines.push(described.length > 0 ? ` },` : ` }`);
39063
+ if (described.length > 0) {
39064
+ const descLines = described.map(function (c) { return ` ${keyToken(c.name)}: ${quote(c.description)}`; });
39065
+ lines.push(` columns: {`);
39066
+ lines.push(descLines.join(",\n"));
39067
+ lines.push(` }`);
39068
+ }
39069
+ lines.push("}");
39070
+ return lines.join("\n") + "\n";
39071
+ }
39072
+ function resolveConnection(projectDir, connectionName) {
39073
+ const workflowSettings = readConfigFromWorkflowSettings(path__namespace.resolve(projectDir));
39074
+ const definition = workflowSettings && workflowSettings.connections
39075
+ ? workflowSettings.connections[connectionName]
39076
+ : undefined;
39077
+ if (!definition) {
39078
+ throw new Error(`Unknown connection "${connectionName}". Define it under \`connections:\` in workflow_settings.yaml.`);
39079
+ }
39080
+ const credsPath = path__namespace.join(path__namespace.resolve(projectDir), ".df-credentials.json");
39081
+ if (!fs__namespace.existsSync(credsPath)) {
39082
+ throw new Error(`Missing .df-credentials.json in ${projectDir}.`);
39083
+ }
39084
+ const allCreds = JSON.parse(fs__namespace.readFileSync(credsPath, "utf8"));
39085
+ const credentials = allCreds[connectionName];
39086
+ if (!credentials) {
39087
+ throw new Error(`No credentials for connection "${connectionName}" in .df-credentials.json ` +
39088
+ `(expected a top-level "${connectionName}" key).`);
39089
+ }
39090
+ return { name: connectionName, definition, credentials };
39091
+ }
39092
+ const readPostgresSchema = function (resolved, sourceSchema, table) {
39093
+ const c = resolved.credentials;
39094
+ const client = new pg__namespace.Client({
39095
+ host: c.host || resolved.definition.host,
39096
+ port: Number(c.port || resolved.definition.port || 5432),
39097
+ database: c.database || resolved.definition.database,
39098
+ user: c.user,
39099
+ password: c.password,
39100
+ ssl: c.sslMode && c.sslMode !== "disable" ? { rejectUnauthorized: false } : undefined
39101
+ });
39102
+ return client
39103
+ .connect()
39104
+ .then(function () {
39105
+ return client.query(`select a.attname as column_name,
39106
+ format_type(a.atttypid, a.atttypmod) as data_type,
39107
+ col_description(a.attrelid, a.attnum) as description
39108
+ from pg_attribute a
39109
+ where a.attrelid = format('%I.%I', $1::text, $2::text)::regclass
39110
+ and a.attnum > 0 and not a.attisdropped
39111
+ order by a.attnum`, [sourceSchema, table]);
39112
+ })
39113
+ .then(function (res) {
39114
+ return res.rows.map(function (r) {
39115
+ return { name: r.column_name, type: r.data_type, description: r.description || undefined };
39116
+ });
39117
+ })
39118
+ .then(function (cols) {
39119
+ return client.end().then(function () {
39120
+ return cols;
39121
+ });
39122
+ }, function (err) {
39123
+ return client.end().then(function () { throw err; }, function () { throw err; });
39124
+ });
39125
+ };
39126
+ const readBigQuerySchema = function (resolved, sourceSchema, table) {
39127
+ const keyJson = resolved.credentials.credentials;
39128
+ const bq = new bigquery.BigQuery({
39129
+ projectId: resolved.definition.project,
39130
+ credentials: typeof keyJson === "string" ? JSON.parse(keyJson) : keyJson
39131
+ });
39132
+ return bq
39133
+ .dataset(sourceSchema)
39134
+ .table(table)
39135
+ .getMetadata()
39136
+ .then(function (result) {
39137
+ const metadata = result[0];
39138
+ const fields = (metadata && metadata.schema && metadata.schema.fields) || [];
39139
+ return fields.map(function (f) {
39140
+ return { name: f.name, type: f.type, description: f.description || undefined };
39141
+ });
39142
+ });
39143
+ };
39144
+ function defaultReaderFor(platform) {
39145
+ if (platform === "bigquery") {
39146
+ return readBigQuerySchema;
39147
+ }
39148
+ if (platform === "postgres" || platform === "supabase") {
39149
+ return readPostgresSchema;
39150
+ }
39151
+ throw new Error(`introspect does not support source platform "${platform}".`);
39152
+ }
39153
+ function splitTableRef(tableRef) {
39154
+ const dot = tableRef.indexOf(".");
39155
+ return dot === -1
39156
+ ? { table: tableRef }
39157
+ : { schema: tableRef.slice(0, dot), table: tableRef.slice(dot + 1) };
39158
+ }
39159
+ function introspectToSqlx(projectDir, connectionName, tableRef, options) {
39160
+ const opts = options || {};
39161
+ const resolved = resolveConnection(projectDir, connectionName);
39162
+ const parts = splitTableRef(tableRef);
39163
+ const reader = opts.reader || defaultReaderFor(resolved.definition.platform);
39164
+ const sourceSchema = parts.schema || resolved.definition.dataset || resolved.definition.defaultSchema;
39165
+ if (!sourceSchema) {
39166
+ return Promise.reject(new Error(`Could not determine the source schema for "${tableRef}" on connection "${connectionName}". ` +
39167
+ `Pass it as "schema.table", or set "dataset"/"defaultSchema" on the connection.`));
39168
+ }
39169
+ const mapType = resolved.definition.platform === "bigquery" ? mapBigQueryType : mapPostgresType;
39170
+ return reader(resolved, sourceSchema, parts.table).then(function (rawColumns) {
39171
+ if (rawColumns.length === 0) {
39172
+ throw new Error(`Source table "${tableRef}" on connection "${connectionName}" has no columns (does it exist?).`);
39173
+ }
39174
+ const columns = rawColumns.map(function (col) {
39175
+ return { name: col.name, type: mapType(col.type), description: col.description };
39176
+ });
39177
+ return renderDeclarationSqlx({
39178
+ connection: connectionName,
39179
+ schema: parts.schema,
39180
+ name: parts.table,
39181
+ columns
39182
+ });
39183
+ });
39184
+ }
39185
+
38412
39186
  function parseArgvFlags(argv) {
38413
39187
  const parsedArgv = {};
38414
39188
  const splitArgv = [];
@@ -41263,7 +42037,7 @@ const warehouseOption = {
41263
42037
  describe: "Target warehouse for the new project.",
41264
42038
  type: "string",
41265
42039
  choices: ["bigquery", "postgres", "supabase"],
41266
- default: "bigquery"
42040
+ default: "supabase"
41267
42041
  }
41268
42042
  };
41269
42043
  const testConnectionOptionName = "test-connection";
@@ -41765,6 +42539,42 @@ function runCli() {
41765
42539
  }
41766
42540
  return 0;
41767
42541
  }
42542
+ },
42543
+ {
42544
+ format: `introspect <connection> <tableRef> [${projectDirOption.name}]`,
42545
+ description: "Read a source table's schema from a connection and write a declaration .sqlx with columnTypes.",
42546
+ positionalOptions: [
42547
+ {
42548
+ name: "connection",
42549
+ option: { describe: "Connection name (from workflow_settings.yaml connections)." }
42550
+ },
42551
+ {
42552
+ name: "tableRef",
42553
+ option: { describe: "Source table as schema.table (or just table)." }
42554
+ },
42555
+ projectDirOption
42556
+ ],
42557
+ options: [
42558
+ {
42559
+ name: "output",
42560
+ option: {
42561
+ describe: "File to write the declaration .sqlx to. Prints to stdout if omitted.",
42562
+ type: "string"
42563
+ }
42564
+ }
42565
+ ],
42566
+ processFn: async (argv) => {
42567
+ const projectDir = argv[projectDirOption.name];
42568
+ const sqlx = await introspectToSqlx(projectDir, argv.connection, argv.tableRef);
42569
+ if (argv.output) {
42570
+ fs__namespace$1.writeFileSync(argv.output, sqlx);
42571
+ printSuccess(`Wrote declaration to ${argv.output}`);
42572
+ }
42573
+ else {
42574
+ print(sqlx);
42575
+ }
42576
+ return 0;
42577
+ }
41768
42578
  }
41769
42579
  ]
41770
42580
  })