outhad-integrations 0.32.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +43 -0
- data/.ruby-version +1 -0
- data/.vscode/settings.json +5 -0
- data/README.md +76 -0
- data/Rakefile +12 -0
- data/lib/outhad/integrations/config.rb +14 -0
- data/lib/outhad/integrations/core/base_connector.rb +79 -0
- data/lib/outhad/integrations/core/constants.rb +103 -0
- data/lib/outhad/integrations/core/destination_connector.rb +20 -0
- data/lib/outhad/integrations/core/fullrefresher.rb +19 -0
- data/lib/outhad/integrations/core/http_client.rb +17 -0
- data/lib/outhad/integrations/core/http_helper.rb +36 -0
- data/lib/outhad/integrations/core/query_builder.rb +33 -0
- data/lib/outhad/integrations/core/rate_limiter.rb +19 -0
- data/lib/outhad/integrations/core/source_connector.rb +66 -0
- data/lib/outhad/integrations/core/streaming_http_client.rb +21 -0
- data/lib/outhad/integrations/core/unstructured_source_connector.rb +52 -0
- data/lib/outhad/integrations/core/utils.rb +123 -0
- data/lib/outhad/integrations/core/vector_source_connector.rb +14 -0
- data/lib/outhad/integrations/destination/airtable/client.rb +157 -0
- data/lib/outhad/integrations/destination/airtable/config/catalog.json +6 -0
- data/lib/outhad/integrations/destination/airtable/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/airtable/config/spec.json +23 -0
- data/lib/outhad/integrations/destination/airtable/icon.svg +6 -0
- data/lib/outhad/integrations/destination/airtable/schema_helper.rb +141 -0
- data/lib/outhad/integrations/destination/ais_data_store/client.rb +130 -0
- data/lib/outhad/integrations/destination/ais_data_store/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/ais_data_store/config/spec.json +68 -0
- data/lib/outhad/integrations/destination/ais_data_store/icon.svg +4 -0
- data/lib/outhad/integrations/destination/amazon_s3/client.rb +92 -0
- data/lib/outhad/integrations/destination/amazon_s3/config/catalog.json +16 -0
- data/lib/outhad/integrations/destination/amazon_s3/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/amazon_s3/config/spec.json +56 -0
- data/lib/outhad/integrations/destination/amazon_s3/icon.svg +34 -0
- data/lib/outhad/integrations/destination/databricks_lakehouse/client.rb +147 -0
- data/lib/outhad/integrations/destination/databricks_lakehouse/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/databricks_lakehouse/config/spec.json +44 -0
- data/lib/outhad/integrations/destination/databricks_lakehouse/icon.svg +65 -0
- data/lib/outhad/integrations/destination/facebook_custom_audience/client.rb +125 -0
- data/lib/outhad/integrations/destination/facebook_custom_audience/config/catalog.json +42 -0
- data/lib/outhad/integrations/destination/facebook_custom_audience/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/facebook_custom_audience/config/spec.json +28 -0
- data/lib/outhad/integrations/destination/facebook_custom_audience/icon.svg +23 -0
- data/lib/outhad/integrations/destination/google_sheets/client.rb +240 -0
- data/lib/outhad/integrations/destination/google_sheets/config/catalog.json +6 -0
- data/lib/outhad/integrations/destination/google_sheets/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/google_sheets/config/spec.json +75 -0
- data/lib/outhad/integrations/destination/google_sheets/icon.svg +1 -0
- data/lib/outhad/integrations/destination/http/client.rb +106 -0
- data/lib/outhad/integrations/destination/http/config/catalog.json +16 -0
- data/lib/outhad/integrations/destination/http/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/http/config/spec.json +24 -0
- data/lib/outhad/integrations/destination/http/icon.svg +9 -0
- data/lib/outhad/integrations/destination/hubspot/client.rb +122 -0
- data/lib/outhad/integrations/destination/hubspot/config/catalog.json +351 -0
- data/lib/outhad/integrations/destination/hubspot/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/hubspot/config/spec.json +18 -0
- data/lib/outhad/integrations/destination/hubspot/icon.svg +5 -0
- data/lib/outhad/integrations/destination/iterable/client.rb +111 -0
- data/lib/outhad/integrations/destination/iterable/config/catalog.json +47 -0
- data/lib/outhad/integrations/destination/iterable/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/iterable/config/spec.json +19 -0
- data/lib/outhad/integrations/destination/iterable/icon.svg +71 -0
- data/lib/outhad/integrations/destination/klaviyo/client.rb +119 -0
- data/lib/outhad/integrations/destination/klaviyo/config/catalog.json +103 -0
- data/lib/outhad/integrations/destination/klaviyo/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/klaviyo/config/spec.json +24 -0
- data/lib/outhad/integrations/destination/klaviyo/icon.svg +6 -0
- data/lib/outhad/integrations/destination/mailchimp/client.rb +141 -0
- data/lib/outhad/integrations/destination/mailchimp/config/catalog.json +142 -0
- data/lib/outhad/integrations/destination/mailchimp/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/mailchimp/config/spec.json +28 -0
- data/lib/outhad/integrations/destination/mailchimp/icon.svg +4 -0
- data/lib/outhad/integrations/destination/maria_db/client.rb +114 -0
- data/lib/outhad/integrations/destination/maria_db/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/maria_db/config/spec.json +48 -0
- data/lib/outhad/integrations/destination/maria_db/icon.svg +15 -0
- data/lib/outhad/integrations/destination/microsoft_dynamics/client.rb +150 -0
- data/lib/outhad/integrations/destination/microsoft_dynamics/config/catalog.json +161 -0
- data/lib/outhad/integrations/destination/microsoft_dynamics/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/microsoft_dynamics/config/spec.json +35 -0
- data/lib/outhad/integrations/destination/microsoft_dynamics/icon.svg +2 -0
- data/lib/outhad/integrations/destination/microsoft_excel/client.rb +198 -0
- data/lib/outhad/integrations/destination/microsoft_excel/config/catalog.json +7 -0
- data/lib/outhad/integrations/destination/microsoft_excel/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/microsoft_excel/config/spec.json +19 -0
- data/lib/outhad/integrations/destination/microsoft_excel/icon.svg +18 -0
- data/lib/outhad/integrations/destination/microsoft_sql/client.rb +137 -0
- data/lib/outhad/integrations/destination/microsoft_sql/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/microsoft_sql/config/spec.json +68 -0
- data/lib/outhad/integrations/destination/microsoft_sql/icon.svg +22 -0
- data/lib/outhad/integrations/destination/odoo/client.rb +109 -0
- data/lib/outhad/integrations/destination/odoo/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/odoo/config/spec.json +39 -0
- data/lib/outhad/integrations/destination/odoo/icon.svg +21 -0
- data/lib/outhad/integrations/destination/oracle_db/client.rb +112 -0
- data/lib/outhad/integrations/destination/oracle_db/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/oracle_db/config/spec.json +47 -0
- data/lib/outhad/integrations/destination/oracle_db/icon.svg +4 -0
- data/lib/outhad/integrations/destination/pinecone_db/client.rb +154 -0
- data/lib/outhad/integrations/destination/pinecone_db/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/pinecone_db/config/spec.json +32 -0
- data/lib/outhad/integrations/destination/pinecone_db/icon.svg +1 -0
- data/lib/outhad/integrations/destination/postgresql/client.rb +130 -0
- data/lib/outhad/integrations/destination/postgresql/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/postgresql/config/spec.json +68 -0
- data/lib/outhad/integrations/destination/postgresql/icon.svg +20 -0
- data/lib/outhad/integrations/destination/qdrant/client.rb +184 -0
- data/lib/outhad/integrations/destination/qdrant/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/qdrant/config/spec.json +23 -0
- data/lib/outhad/integrations/destination/qdrant/icon.svg +1 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/client.rb +136 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/config/catalog.json +6 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/config/meta.json +16 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/config/spec.json +52 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/icon.svg +16 -0
- data/lib/outhad/integrations/destination/salesforce_consumer_goods_cloud/schema_helper.rb +132 -0
- data/lib/outhad/integrations/destination/salesforce_crm/client.rb +114 -0
- data/lib/outhad/integrations/destination/salesforce_crm/config/catalog.json +320 -0
- data/lib/outhad/integrations/destination/salesforce_crm/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/salesforce_crm/config/spec.json +46 -0
- data/lib/outhad/integrations/destination/salesforce_crm/icon.svg +16 -0
- data/lib/outhad/integrations/destination/sftp/client.rb +186 -0
- data/lib/outhad/integrations/destination/sftp/config/catalog.json +16 -0
- data/lib/outhad/integrations/destination/sftp/config/meta.json +16 -0
- data/lib/outhad/integrations/destination/sftp/config/spec.json +73 -0
- data/lib/outhad/integrations/destination/sftp/icon.svg +1 -0
- data/lib/outhad/integrations/destination/slack/client.rb +125 -0
- data/lib/outhad/integrations/destination/slack/config/catalog.json +22 -0
- data/lib/outhad/integrations/destination/slack/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/slack/config/spec.json +23 -0
- data/lib/outhad/integrations/destination/slack/icon.svg +26 -0
- data/lib/outhad/integrations/destination/stripe/client.rb +94 -0
- data/lib/outhad/integrations/destination/stripe/config/catalog.json +128 -0
- data/lib/outhad/integrations/destination/stripe/config/meta.json +15 -0
- data/lib/outhad/integrations/destination/stripe/config/spec.json +18 -0
- data/lib/outhad/integrations/destination/stripe/icon.svg +10 -0
- data/lib/outhad/integrations/destination/zendesk/client.rb +132 -0
- data/lib/outhad/integrations/destination/zendesk/config/catalog.json +110 -0
- data/lib/outhad/integrations/destination/zendesk/config/meta.json +18 -0
- data/lib/outhad/integrations/destination/zendesk/config/spec.json +32 -0
- data/lib/outhad/integrations/destination/zendesk/icon.svg +63 -0
- data/lib/outhad/integrations/protocol/protocol.json +189 -0
- data/lib/outhad/integrations/protocol/protocol.rb +228 -0
- data/lib/outhad/integrations/rollout.rb +66 -0
- data/lib/outhad/integrations/service.rb +55 -0
- data/lib/outhad/integrations/source/amazon_s3/client.rb +235 -0
- data/lib/outhad/integrations/source/amazon_s3/config/meta.json +16 -0
- data/lib/outhad/integrations/source/amazon_s3/config/spec.json +119 -0
- data/lib/outhad/integrations/source/amazon_s3/icon.svg +34 -0
- data/lib/outhad/integrations/source/anthropic/client.rb +135 -0
- data/lib/outhad/integrations/source/anthropic/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/anthropic/config/meta.json +16 -0
- data/lib/outhad/integrations/source/anthropic/config/spec.json +56 -0
- data/lib/outhad/integrations/source/anthropic/icon.svg +1 -0
- data/lib/outhad/integrations/source/aws_athena/client.rb +109 -0
- data/lib/outhad/integrations/source/aws_athena/config/meta.json +16 -0
- data/lib/outhad/integrations/source/aws_athena/config/spec.json +63 -0
- data/lib/outhad/integrations/source/aws_athena/icon.svg +22 -0
- data/lib/outhad/integrations/source/aws_bedrock_model/client.rb +91 -0
- data/lib/outhad/integrations/source/aws_bedrock_model/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/aws_bedrock_model/config/meta.json +16 -0
- data/lib/outhad/integrations/source/aws_bedrock_model/config/spec.json +58 -0
- data/lib/outhad/integrations/source/aws_bedrock_model/icon.svg +1 -0
- data/lib/outhad/integrations/source/aws_sagemaker_model/client.rb +79 -0
- data/lib/outhad/integrations/source/aws_sagemaker_model/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/aws_sagemaker_model/config/meta.json +16 -0
- data/lib/outhad/integrations/source/aws_sagemaker_model/config/spec.json +52 -0
- data/lib/outhad/integrations/source/aws_sagemaker_model/icon.svg +7 -0
- data/lib/outhad/integrations/source/bigquery/client.rb +98 -0
- data/lib/outhad/integrations/source/bigquery/config/meta.json +16 -0
- data/lib/outhad/integrations/source/bigquery/config/spec.json +83 -0
- data/lib/outhad/integrations/source/bigquery/icon.svg +1 -0
- data/lib/outhad/integrations/source/clickhouse/client.rb +102 -0
- data/lib/outhad/integrations/source/clickhouse/config/meta.json +16 -0
- data/lib/outhad/integrations/source/clickhouse/config/spec.json +42 -0
- data/lib/outhad/integrations/source/clickhouse/icon.svg +25 -0
- data/lib/outhad/integrations/source/databricks/client.rb +98 -0
- data/lib/outhad/integrations/source/databricks/config/meta.json +17 -0
- data/lib/outhad/integrations/source/databricks/config/spec.json +56 -0
- data/lib/outhad/integrations/source/databricks/icon.svg +19 -0
- data/lib/outhad/integrations/source/databrics_model/client.rb +89 -0
- data/lib/outhad/integrations/source/databrics_model/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/databrics_model/config/meta.json +17 -0
- data/lib/outhad/integrations/source/databrics_model/config/spec.json +63 -0
- data/lib/outhad/integrations/source/databrics_model/icon.svg +19 -0
- data/lib/outhad/integrations/source/firecrawl/client.rb +151 -0
- data/lib/outhad/integrations/source/firecrawl/config/catalog.json +29 -0
- data/lib/outhad/integrations/source/firecrawl/config/meta.json +17 -0
- data/lib/outhad/integrations/source/firecrawl/config/spec.json +31 -0
- data/lib/outhad/integrations/source/firecrawl/icon.svg +4 -0
- data/lib/outhad/integrations/source/generic_open_ai/client.rb +118 -0
- data/lib/outhad/integrations/source/generic_open_ai/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/generic_open_ai/config/meta.json +16 -0
- data/lib/outhad/integrations/source/generic_open_ai/config/spec.json +63 -0
- data/lib/outhad/integrations/source/generic_open_ai/icon.svg +6 -0
- data/lib/outhad/integrations/source/google_vertex_model/client.rb +83 -0
- data/lib/outhad/integrations/source/google_vertex_model/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/google_vertex_model/config/meta.json +17 -0
- data/lib/outhad/integrations/source/google_vertex_model/config/spec.json +105 -0
- data/lib/outhad/integrations/source/google_vertex_model/icon.svg +2 -0
- data/lib/outhad/integrations/source/http_model/client.rb +108 -0
- data/lib/outhad/integrations/source/http_model/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/http_model/config/meta.json +16 -0
- data/lib/outhad/integrations/source/http_model/config/spec.json +70 -0
- data/lib/outhad/integrations/source/http_model/icon.svg +9 -0
- data/lib/outhad/integrations/source/intuit_quick_books/client.rb +213 -0
- data/lib/outhad/integrations/source/intuit_quick_books/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/intuit_quick_books/config/meta.json +17 -0
- data/lib/outhad/integrations/source/intuit_quick_books/config/spec.json +44 -0
- data/lib/outhad/integrations/source/intuit_quick_books/icon.svg +1 -0
- data/lib/outhad/integrations/source/maria_db/client.rb +92 -0
- data/lib/outhad/integrations/source/maria_db/config/meta.json +16 -0
- data/lib/outhad/integrations/source/maria_db/config/spec.json +48 -0
- data/lib/outhad/integrations/source/maria_db/icon.svg +15 -0
- data/lib/outhad/integrations/source/odoo/client.rb +106 -0
- data/lib/outhad/integrations/source/odoo/config/meta.json +15 -0
- data/lib/outhad/integrations/source/odoo/config/spec.json +39 -0
- data/lib/outhad/integrations/source/odoo/icon.svg +21 -0
- data/lib/outhad/integrations/source/open_ai/client.rb +118 -0
- data/lib/outhad/integrations/source/open_ai/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/open_ai/config/meta.json +16 -0
- data/lib/outhad/integrations/source/open_ai/config/spec.json +56 -0
- data/lib/outhad/integrations/source/open_ai/icon.svg +1 -0
- data/lib/outhad/integrations/source/oracle_db/client.rb +127 -0
- data/lib/outhad/integrations/source/oracle_db/config/meta.json +16 -0
- data/lib/outhad/integrations/source/oracle_db/config/spec.json +47 -0
- data/lib/outhad/integrations/source/oracle_db/icon.svg +4 -0
- data/lib/outhad/integrations/source/pinecone_db/client.rb +73 -0
- data/lib/outhad/integrations/source/pinecone_db/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/pinecone_db/config/meta.json +16 -0
- data/lib/outhad/integrations/source/pinecone_db/config/spec.json +34 -0
- data/lib/outhad/integrations/source/pinecone_db/icon.svg +2 -0
- data/lib/outhad/integrations/source/postgresql/client.rb +112 -0
- data/lib/outhad/integrations/source/postgresql/config/meta.json +16 -0
- data/lib/outhad/integrations/source/postgresql/config/spec.json +86 -0
- data/lib/outhad/integrations/source/postgresql/icon.svg +20 -0
- data/lib/outhad/integrations/source/qdrant/client.rb +86 -0
- data/lib/outhad/integrations/source/qdrant/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/qdrant/config/meta.json +16 -0
- data/lib/outhad/integrations/source/qdrant/config/spec.json +29 -0
- data/lib/outhad/integrations/source/qdrant/icon.svg +1 -0
- data/lib/outhad/integrations/source/redshift/client.rb +109 -0
- data/lib/outhad/integrations/source/redshift/config/meta.json +16 -0
- data/lib/outhad/integrations/source/redshift/config/spec.json +71 -0
- data/lib/outhad/integrations/source/redshift/icon.svg +15 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/client.rb +133 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/config/meta.json +18 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/config/spec.json +53 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/icon.svg +16 -0
- data/lib/outhad/integrations/source/salesforce_consumer_goods_cloud/schema_helper.rb +130 -0
- data/lib/outhad/integrations/source/sftp/client.rb +133 -0
- data/lib/outhad/integrations/source/sftp/config/meta.json +16 -0
- data/lib/outhad/integrations/source/sftp/config/spec.json +59 -0
- data/lib/outhad/integrations/source/sftp/icon.svg +1 -0
- data/lib/outhad/integrations/source/snowflake/client.rb +92 -0
- data/lib/outhad/integrations/source/snowflake/config/meta.json +16 -0
- data/lib/outhad/integrations/source/snowflake/config/spec.json +82 -0
- data/lib/outhad/integrations/source/snowflake/icon.svg +10 -0
- data/lib/outhad/integrations/source/watsonx_ai/client.rb +194 -0
- data/lib/outhad/integrations/source/watsonx_ai/config/catalog.json +6 -0
- data/lib/outhad/integrations/source/watsonx_ai/config/meta.json +16 -0
- data/lib/outhad/integrations/source/watsonx_ai/config/spec.json +74 -0
- data/lib/outhad/integrations/source/watsonx_ai/icon.svg +1 -0
- data/lib/outhad/integrations/source/watsonx_data/client.rb +146 -0
- data/lib/outhad/integrations/source/watsonx_data/config/meta.json +17 -0
- data/lib/outhad/integrations/source/watsonx_data/config/spec.json +72 -0
- data/lib/outhad/integrations/source/watsonx_data/icon.svg +1 -0
- data/lib/outhad/integrations.rb +129 -0
- data/outhad-integrations.gemspec +79 -0
- data/sig/outhad/integrations.rbs +6 -0
- metadata +866 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Outhad
|
4
|
+
module Integrations::Core
|
5
|
+
module Utils
|
6
|
+
def keys_to_symbols(hash)
|
7
|
+
if hash.is_a?(Hash)
|
8
|
+
hash.each_with_object({}) do |(key, value), result|
|
9
|
+
result[key.to_sym] = keys_to_symbols(value)
|
10
|
+
end
|
11
|
+
elsif hash.is_a?(Array)
|
12
|
+
hash.map { |item| keys_to_symbols(item) }
|
13
|
+
else
|
14
|
+
hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_to_json_schema(column_definitions)
|
19
|
+
json_schema = {
|
20
|
+
"type" => "object",
|
21
|
+
"properties" => {}
|
22
|
+
}
|
23
|
+
|
24
|
+
column_definitions.each do |column|
|
25
|
+
column_name = column[:column_name]
|
26
|
+
type = column[:type]
|
27
|
+
optional = column[:optional]
|
28
|
+
json_type = map_type_to_json_schema(type)
|
29
|
+
json_schema["properties"][column_name] = {
|
30
|
+
"type" => json_type
|
31
|
+
}
|
32
|
+
json_schema["properties"][column_name]["type"] = [json_type, "null"] if optional
|
33
|
+
end
|
34
|
+
|
35
|
+
json_schema
|
36
|
+
end
|
37
|
+
|
38
|
+
def map_type_to_json_schema(type)
|
39
|
+
case type
|
40
|
+
when "NUMBER"
|
41
|
+
"integer"
|
42
|
+
when "vector"
|
43
|
+
"vector"
|
44
|
+
else
|
45
|
+
"string" # Default type
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def logger
|
50
|
+
Integrations::Service.logger
|
51
|
+
end
|
52
|
+
|
53
|
+
def report_exception(exception, meta = {})
|
54
|
+
reporter = Integrations::Service.exception_reporter
|
55
|
+
reporter&.report(exception, meta)
|
56
|
+
end
|
57
|
+
|
58
|
+
def log_request_response(level, request, response)
|
59
|
+
Integrations::Protocol::LogMessage.new(
|
60
|
+
name: self.class.name,
|
61
|
+
level: level,
|
62
|
+
message: { request: request.to_s, response: response.to_s, level: level }.to_json
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_log_message(context, type, message)
|
67
|
+
Integrations::Protocol::LogMessage.new(
|
68
|
+
name: context,
|
69
|
+
level: type,
|
70
|
+
message: message
|
71
|
+
).to_outhad_message
|
72
|
+
end
|
73
|
+
|
74
|
+
def handle_exception(exception, meta = {})
|
75
|
+
logger.error(
|
76
|
+
"#{hash_to_string(meta)}: #{exception.message}"
|
77
|
+
)
|
78
|
+
report_exception(exception, meta)
|
79
|
+
create_log_message(meta[:context], meta[:type], exception.message)
|
80
|
+
end
|
81
|
+
|
82
|
+
def hash_to_string(hash)
|
83
|
+
hash.map { |key, value| "#{key} = #{value}" }.join(", ")
|
84
|
+
end
|
85
|
+
|
86
|
+
def extract_data(record_object, properties)
|
87
|
+
data_attributes = record_object.with_indifferent_access
|
88
|
+
data_attributes.select { |key, _| properties.key?(key.to_sym) }
|
89
|
+
end
|
90
|
+
|
91
|
+
def success?(response)
|
92
|
+
response && %w[200 201].include?(response.code.to_s)
|
93
|
+
end
|
94
|
+
|
95
|
+
def build_catalog(catalog_json)
|
96
|
+
streams = catalog_json["streams"].map { |stream_json| build_stream(stream_json) }
|
97
|
+
Outhad::Integrations::Protocol::Catalog.new(
|
98
|
+
streams: streams,
|
99
|
+
request_rate_limit: catalog_json["request_rate_limit"] || 60,
|
100
|
+
request_rate_limit_unit: catalog_json["request_rate_limit_unit"] || "minute",
|
101
|
+
request_rate_concurrency: catalog_json["request_rate_concurrency"] || 10,
|
102
|
+
schema_mode: catalog_json["schema_mode"] || "schema"
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def build_stream(stream_json)
|
107
|
+
Outhad::Integrations::Protocol::Stream.new(
|
108
|
+
name: stream_json["name"],
|
109
|
+
url: stream_json["url"],
|
110
|
+
action: stream_json["action"],
|
111
|
+
request_method: stream_json["method"],
|
112
|
+
batch_support: stream_json["batch_support"] || false,
|
113
|
+
batch_size: stream_json["batch_size"] || 1,
|
114
|
+
json_schema: stream_json["json_schema"],
|
115
|
+
request_rate_limit: stream_json["request_rate_limit"].to_i,
|
116
|
+
request_rate_limit_unit: stream_json["request_rate_limit_unit"] || "minute",
|
117
|
+
request_rate_concurrency: stream_json["request_rate_concurrency"].to_i,
|
118
|
+
supported_sync_modes: stream_json["supported_sync_modes"]
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Outhad
|
4
|
+
module Integrations::Core
|
5
|
+
class VectorSourceConnector < SourceConnector
|
6
|
+
# This needs to be implemented
|
7
|
+
# for all vector database sources
|
8
|
+
# that will be used in RAG workflows
|
9
|
+
def search(_vector_search_config)
|
10
|
+
raise "Not implemented"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "schema_helper"
|
4
|
+
module Outhad
|
5
|
+
module Integrations
|
6
|
+
module Destination
|
7
|
+
module Airtable
|
8
|
+
include Outhad::Integrations::Core
|
9
|
+
class Client < DestinationConnector
|
10
|
+
prepend Outhad::Integrations::Core::RateLimiter
|
11
|
+
MAX_CHUNK_SIZE = 10
|
12
|
+
def check_connection(connection_config)
|
13
|
+
connection_config = connection_config.with_indifferent_access
|
14
|
+
bases = Outhad::Integrations::Core::HttpClient.request(
|
15
|
+
AIRTABLE_BASES_ENDPOINT,
|
16
|
+
HTTP_GET,
|
17
|
+
headers: auth_headers(connection_config[:api_key])
|
18
|
+
)
|
19
|
+
if success?(bases)
|
20
|
+
base_id_exists?(bases, connection_config[:base_id])
|
21
|
+
success_status
|
22
|
+
else
|
23
|
+
failure_status(nil)
|
24
|
+
end
|
25
|
+
rescue StandardError => e
|
26
|
+
failure_status(e)
|
27
|
+
end
|
28
|
+
|
29
|
+
def discover(connection_config)
|
30
|
+
connection_config = connection_config.with_indifferent_access
|
31
|
+
base_id = connection_config[:base_id]
|
32
|
+
api_key = connection_config[:api_key]
|
33
|
+
|
34
|
+
bases = Outhad::Integrations::Core::HttpClient.request(
|
35
|
+
AIRTABLE_BASES_ENDPOINT,
|
36
|
+
HTTP_GET,
|
37
|
+
headers: auth_headers(api_key)
|
38
|
+
)
|
39
|
+
|
40
|
+
base = extract_bases(bases).find { |b| b["id"] == base_id }
|
41
|
+
base_name = base["name"]
|
42
|
+
|
43
|
+
schema = Outhad::Integrations::Core::HttpClient.request(
|
44
|
+
AIRTABLE_GET_BASE_SCHEMA_ENDPOINT.gsub("{baseId}", base_id),
|
45
|
+
HTTP_GET,
|
46
|
+
headers: auth_headers(api_key)
|
47
|
+
)
|
48
|
+
|
49
|
+
catalog = build_catalog_from_schema(extract_body(schema), base_id, base_name)
|
50
|
+
catalog.to_outhad_message
|
51
|
+
rescue StandardError => e
|
52
|
+
handle_exception(e, {
|
53
|
+
context: "AIRTABLE:DISCOVER:EXCEPTION",
|
54
|
+
type: "error"
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def write(sync_config, records, _action = "create")
|
59
|
+
connection_config = sync_config.destination.connection_specification.with_indifferent_access
|
60
|
+
api_key = connection_config[:api_key]
|
61
|
+
url = sync_config.stream.url
|
62
|
+
log_message_array = []
|
63
|
+
write_success = 0
|
64
|
+
write_failure = 0
|
65
|
+
records.each_slice(MAX_CHUNK_SIZE) do |chunk|
|
66
|
+
payload = create_payload(chunk)
|
67
|
+
args = [sync_config.stream.request_method, url, payload]
|
68
|
+
response = Outhad::Integrations::Core::HttpClient.request(
|
69
|
+
url,
|
70
|
+
sync_config.stream.request_method,
|
71
|
+
payload: payload,
|
72
|
+
headers: auth_headers(api_key)
|
73
|
+
)
|
74
|
+
if success?(response)
|
75
|
+
write_success += chunk.size
|
76
|
+
else
|
77
|
+
write_failure += chunk.size
|
78
|
+
end
|
79
|
+
log_message_array << log_request_response("info", args, response)
|
80
|
+
rescue StandardError => e
|
81
|
+
handle_exception(e, {
|
82
|
+
context: "AIRTABLE:RECORD:WRITE:EXCEPTION",
|
83
|
+
type: "error",
|
84
|
+
sync_id: sync_config.sync_id,
|
85
|
+
sync_run_id: sync_config.sync_run_id
|
86
|
+
})
|
87
|
+
write_failure += chunk.size
|
88
|
+
log_message_array << log_request_response("error", args, e.message)
|
89
|
+
end
|
90
|
+
tracking_message(write_success, write_failure, log_message_array)
|
91
|
+
rescue StandardError => e
|
92
|
+
handle_exception(e, {
|
93
|
+
context: "AIRTABLE:RECORD:WRITE:EXCEPTION",
|
94
|
+
type: "error",
|
95
|
+
sync_id: sync_config.sync_id,
|
96
|
+
sync_run_id: sync_config.sync_run_id
|
97
|
+
})
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def create_payload(records)
|
103
|
+
{
|
104
|
+
"records" => records.map do |record|
|
105
|
+
{
|
106
|
+
"fields" => record
|
107
|
+
}
|
108
|
+
end
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def base_id_exists?(bases, base_id)
|
113
|
+
return if extract_bases(bases).any? { |base| base["id"] == base_id }
|
114
|
+
|
115
|
+
raise ArgumentError, "base_id not found"
|
116
|
+
end
|
117
|
+
|
118
|
+
def extract_bases(response)
|
119
|
+
response_body = extract_body(response)
|
120
|
+
response_body["bases"] if response_body
|
121
|
+
end
|
122
|
+
|
123
|
+
def extract_body(response)
|
124
|
+
response_body = response.body
|
125
|
+
JSON.parse(response_body) if response_body
|
126
|
+
end
|
127
|
+
|
128
|
+
def load_catalog
|
129
|
+
read_json(CATALOG_SPEC_PATH)
|
130
|
+
end
|
131
|
+
|
132
|
+
def create_stream(table, base_id, base_name)
|
133
|
+
{
|
134
|
+
name: "#{base_name}/#{SchemaHelper.clean_name(table["name"])}",
|
135
|
+
action: "create",
|
136
|
+
method: HTTP_POST,
|
137
|
+
url: "#{AIRTABLE_URL_BASE}#{base_id}/#{table["id"]}",
|
138
|
+
json_schema: SchemaHelper.get_json_schema(table),
|
139
|
+
supported_sync_modes: %w[incremental],
|
140
|
+
batch_support: true,
|
141
|
+
batch_size: 10
|
142
|
+
|
143
|
+
}.with_indifferent_access
|
144
|
+
end
|
145
|
+
|
146
|
+
def build_catalog_from_schema(schema, base_id, base_name)
|
147
|
+
catalog = build_catalog(load_catalog)
|
148
|
+
schema["tables"].each do |table|
|
149
|
+
catalog.streams << build_stream(create_stream(table, base_id, base_name))
|
150
|
+
end
|
151
|
+
catalog
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"name": "Airtable",
|
4
|
+
"title": "Airtable",
|
5
|
+
"connector_type": "destination",
|
6
|
+
"category": "Productivity Tools",
|
7
|
+
"documentation_url": "https://docs.squared.ai/guides/destinations/retl-destinations/productivity-tools/airtable",
|
8
|
+
"github_issue_label": "destination-airtable",
|
9
|
+
"icon": "icon.svg",
|
10
|
+
"license": "MIT",
|
11
|
+
"release_stage": "alpha",
|
12
|
+
"support_level": "community",
|
13
|
+
"tags": ["language:ruby", "outhad"]
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"documentation_url": "https://docs.squared.ai/guides/destinations/retl-destinations/productivity-tools/airtable",
|
3
|
+
"stream_type": "dynamic",
|
4
|
+
"connection_specification": {
|
5
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
6
|
+
"title": "Airtable",
|
7
|
+
"type": "object",
|
8
|
+
"required": ["api_key", "base_id"],
|
9
|
+
"properties": {
|
10
|
+
"api_key": {
|
11
|
+
"type": "string",
|
12
|
+
"outhad_secret": true,
|
13
|
+
"title": "Personal access token",
|
14
|
+
"order": 0
|
15
|
+
},
|
16
|
+
"base_id": {
|
17
|
+
"type": "string",
|
18
|
+
"title": "Airtable base id",
|
19
|
+
"order": 1
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="27" shape-rendering="geometricPrecision" viewBox="0 0 200 170">
|
2
|
+
<path fill="#FCB400" d="M90.039 12.367L24.079 39.66c-3.667 1.519-3.63 6.729.062 8.192l66.235 26.266a24.575 24.575 0 0018.12 0l66.236-26.266c3.69-1.463 3.729-6.673.06-8.191l-65.958-27.294a24.578 24.578 0 00-18.795 0"></path>
|
3
|
+
<path fill="#18BFFF" d="M105.312 88.46v65.617c0 3.12 3.147 5.258 6.048 4.108l73.806-28.648a4.418 4.418 0 002.79-4.108V59.813c0-3.121-3.147-5.258-6.048-4.108l-73.806 28.648a4.42 4.42 0 00-2.79 4.108"></path>
|
4
|
+
<path fill="#F82B60" d="M88.078 91.846l-21.904 10.576-2.224 1.075-46.238 22.155c-2.93 1.414-6.672-.722-6.672-3.978V60.088c0-1.178.604-2.195 1.414-2.96a5.024 5.024 0 011.12-.84c1.104-.663 2.68-.84 4.02-.31L87.71 83.76c3.564 1.414 3.844 6.408.368 8.087"></path>
|
5
|
+
<path fill="rgba(0, 0, 0, 0.25)" d="M88.078 91.846l-21.904 10.576-53.72-45.295a5.024 5.024 0 011.12-.839c1.104-.663 2.68-.84 4.02-.31L87.71 83.76c3.564 1.414 3.844 6.408.368 8.087"></path>
|
6
|
+
</svg>
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Outhad
|
4
|
+
module Integrations
|
5
|
+
module Destination
|
6
|
+
module Airtable
|
7
|
+
module SchemaHelper
|
8
|
+
include Core::Constants
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def clean_name(name_str)
|
13
|
+
name_str.strip.gsub(" ", "_")
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_json_schema(table)
|
17
|
+
fields = table["fields"] || {}
|
18
|
+
properties = fields.each_with_object({}) do |field, props|
|
19
|
+
name, schema = process_field(field)
|
20
|
+
props[name] = schema
|
21
|
+
end
|
22
|
+
|
23
|
+
build_schema(properties)
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_field(field)
|
27
|
+
name = clean_name(field.fetch("name", ""))
|
28
|
+
original_type = field.fetch("type", "")
|
29
|
+
options = field.fetch("options", {})
|
30
|
+
|
31
|
+
schema = determine_schema(original_type, options)
|
32
|
+
[name, schema]
|
33
|
+
end
|
34
|
+
|
35
|
+
def determine_schema(original_type, options)
|
36
|
+
if COMPLEX_AIRTABLE_TYPES.keys.include?(original_type)
|
37
|
+
complex_type = deep_copy(COMPLEX_AIRTABLE_TYPES[original_type])
|
38
|
+
adjust_complex_type(original_type, complex_type, options)
|
39
|
+
elsif SIMPLE_AIRTABLE_TYPES.keys.include?(original_type)
|
40
|
+
simple_type_schema(original_type, options)
|
41
|
+
else
|
42
|
+
SCHEMA_TYPES[:STRING]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def adjust_complex_type(original_type, complex_type, options)
|
47
|
+
exec_type = options.dig("result", "type") || "simpleText"
|
48
|
+
if complex_type == SCHEMA_TYPES[:ARRAY_WITH_ANY]
|
49
|
+
adjust_array_with_any(original_type, complex_type, exec_type, options)
|
50
|
+
else
|
51
|
+
complex_type
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def adjust_array_with_any(original_type, complex_type, exec_type, options)
|
56
|
+
if original_type == "formula" && %w[number currency percent duration].include?(exec_type)
|
57
|
+
complex_type = SCHEMA_TYPES[:NUMBER]
|
58
|
+
elsif original_type == "formula" && ARRAY_FORMULAS.none? { |x| options.fetch("formula", "").start_with?(x) }
|
59
|
+
complex_type = SCHEMA_TYPES[:STRING]
|
60
|
+
elsif SIMPLE_AIRTABLE_TYPES.keys.include?(exec_type)
|
61
|
+
complex_type["items"] = deep_copy(SIMPLE_AIRTABLE_TYPES[exec_type])
|
62
|
+
else
|
63
|
+
complex_type["items"] = SCHEMA_TYPES[:STRING]
|
64
|
+
end
|
65
|
+
complex_type
|
66
|
+
end
|
67
|
+
|
68
|
+
def simple_type_schema(original_type, options)
|
69
|
+
exec_type = options.dig("result", "type") || original_type
|
70
|
+
deep_copy(SIMPLE_AIRTABLE_TYPES[exec_type])
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_schema(properties)
|
74
|
+
{
|
75
|
+
"$schema" => JSON_SCHEMA_URL,
|
76
|
+
"type" => "object",
|
77
|
+
"additionalProperties" => true,
|
78
|
+
"properties" => properties
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def deep_copy(object)
|
83
|
+
Marshal.load(Marshal.dump(object))
|
84
|
+
end
|
85
|
+
|
86
|
+
SCHEMA_TYPES = {
|
87
|
+
STRING: { "type": %w[null string] },
|
88
|
+
NUMBER: { "type": %w[null number] },
|
89
|
+
BOOLEAN: { "type": %w[null boolean] },
|
90
|
+
DATE: { "type": %w[null string], "format": "date" },
|
91
|
+
DATETIME: { "type": %w[null string], "format": "date-time" },
|
92
|
+
ARRAY_WITH_STRINGS: { "type": %w[null array], "items": { "type": %w[null string] } },
|
93
|
+
ARRAY_WITH_ANY: { "type": %w[null array], "items": {} }
|
94
|
+
}.freeze.with_indifferent_access
|
95
|
+
|
96
|
+
SIMPLE_AIRTABLE_TYPES = {
|
97
|
+
"multipleAttachments" => SCHEMA_TYPES[:STRING],
|
98
|
+
"autoNumber" => SCHEMA_TYPES[:NUMBER],
|
99
|
+
"barcode" => SCHEMA_TYPES[:STRING],
|
100
|
+
"button" => SCHEMA_TYPES[:STRING],
|
101
|
+
"checkbox" => :BOOLEAN,
|
102
|
+
"singleCollaborator" => SCHEMA_TYPES[:STRING],
|
103
|
+
"count" => SCHEMA_TYPES[:NUMBER],
|
104
|
+
"createdBy" => SCHEMA_TYPES[:STRING],
|
105
|
+
"createdTime" => SCHEMA_TYPES[:DATETIME],
|
106
|
+
"currency" => SCHEMA_TYPES[:NUMBER],
|
107
|
+
"email" => SCHEMA_TYPES[:STRING],
|
108
|
+
"date" => SCHEMA_TYPES[:DATE],
|
109
|
+
"dateTime" => SCHEMA_TYPES[:DATETIME],
|
110
|
+
"duration" => SCHEMA_TYPES[:NUMBER],
|
111
|
+
"lastModifiedBy" => SCHEMA_TYPES[:STRING],
|
112
|
+
"lastModifiedTime" => SCHEMA_TYPES[:DATETIME],
|
113
|
+
"multipleRecordLinks" => SCHEMA_TYPES[:ARRAY_WITH_STRINGS],
|
114
|
+
"multilineText" => SCHEMA_TYPES[:STRING],
|
115
|
+
"multipleCollaborators" => SCHEMA_TYPES[:ARRAY_WITH_STRINGS],
|
116
|
+
"multipleSelects" => SCHEMA_TYPES[:ARRAY_WITH_STRINGS],
|
117
|
+
"number" => SCHEMA_TYPES[:NUMBER],
|
118
|
+
"percent" => SCHEMA_TYPES[:NUMBER],
|
119
|
+
"phoneNumber" => SCHEMA_TYPES[:STRING],
|
120
|
+
"rating" => SCHEMA_TYPES[:NUMBER],
|
121
|
+
"richText" => SCHEMA_TYPES[:STRING],
|
122
|
+
"singleLineText" => SCHEMA_TYPES[:STRING],
|
123
|
+
"singleSelect" => SCHEMA_TYPES[:STRING],
|
124
|
+
"externalSyncSource" => SCHEMA_TYPES[:STRING],
|
125
|
+
"url" => SCHEMA_TYPES[:STRING],
|
126
|
+
"simpleText" => SCHEMA_TYPES[:STRING]
|
127
|
+
}.freeze
|
128
|
+
|
129
|
+
COMPLEX_AIRTABLE_TYPES = {
|
130
|
+
"formula" => SCHEMA_TYPES[:ARRAY_WITH_ANY],
|
131
|
+
"lookup" => SCHEMA_TYPES[:ARRAY_WITH_ANY],
|
132
|
+
"multipleLookupValues" => SCHEMA_TYPES[:ARRAY_WITH_ANY],
|
133
|
+
"rollup" => SCHEMA_TYPES[:ARRAY_WITH_ANY]
|
134
|
+
}.freeze.with_indifferent_access
|
135
|
+
|
136
|
+
ARRAY_FORMULAS = %w[ARRAYCOMPACT ARRAYFLATTEN ARRAYUNIQUE ARRAYSLICE].freeze
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pg"
|
4
|
+
|
5
|
+
module Outhad::Integrations::Destination
|
6
|
+
module AISDataStore
|
7
|
+
include Outhad::Integrations::Core
|
8
|
+
class Client < DestinationConnector
|
9
|
+
def check_connection(connection_config)
|
10
|
+
connection_config = connection_config.with_indifferent_access
|
11
|
+
create_connection(connection_config)
|
12
|
+
ConnectionStatus.new(
|
13
|
+
status: ConnectionStatusType["succeeded"]
|
14
|
+
).to_outhad_message
|
15
|
+
rescue PG::Error => e
|
16
|
+
ConnectionStatus.new(
|
17
|
+
status: ConnectionStatusType["failed"], message: e.message
|
18
|
+
).to_outhad_message
|
19
|
+
end
|
20
|
+
|
21
|
+
def discover(connection_config)
|
22
|
+
connection_config = connection_config.with_indifferent_access
|
23
|
+
query = "SELECT table_name, column_name,
|
24
|
+
CASE WHEN data_type = 'USER-DEFINED' THEN udt_name ELSE data_type END
|
25
|
+
AS data_type,
|
26
|
+
is_nullable
|
27
|
+
FROM information_schema.columns
|
28
|
+
WHERE table_schema = '#{connection_config[:schema]}' AND table_catalog = '#{connection_config[:database]}'
|
29
|
+
ORDER BY table_name, ordinal_position;"
|
30
|
+
|
31
|
+
db = create_connection(connection_config)
|
32
|
+
records = db.exec(query) do |result|
|
33
|
+
result.map do |row|
|
34
|
+
row
|
35
|
+
end
|
36
|
+
end
|
37
|
+
catalog = Catalog.new(streams: create_streams(records))
|
38
|
+
catalog.to_outhad_message
|
39
|
+
rescue StandardError => e
|
40
|
+
handle_exception(e, {
|
41
|
+
context: "AIS:DATA:STORE:DISCOVER:EXCEPTION",
|
42
|
+
type: "error"
|
43
|
+
})
|
44
|
+
ensure
|
45
|
+
db&.close
|
46
|
+
end
|
47
|
+
|
48
|
+
def write(sync_config, records, action = "destination_insert")
|
49
|
+
connection_config = sync_config.destination.connection_specification.with_indifferent_access
|
50
|
+
table_name = sync_config.stream.name
|
51
|
+
primary_key = sync_config.model.primary_key
|
52
|
+
log_message_array = []
|
53
|
+
db = create_connection(connection_config)
|
54
|
+
|
55
|
+
write_success = 0
|
56
|
+
write_failure = 0
|
57
|
+
|
58
|
+
records.each do |record|
|
59
|
+
query = Outhad::Integrations::Core::QueryBuilder.perform(action, table_name, record, primary_key)
|
60
|
+
logger.debug("AIS:DATA:STORE:WRITE:QUERY query = #{query} sync_id = #{sync_config.sync_id} sync_run_id = #{sync_config.sync_run_id}")
|
61
|
+
begin
|
62
|
+
response = db.exec(query)
|
63
|
+
write_success += 1
|
64
|
+
log_message_array << log_request_response("info", query, response)
|
65
|
+
rescue StandardError => e
|
66
|
+
handle_exception(e, {
|
67
|
+
context: "AIS:DATA:STORE:RECORD:WRITE:EXCEPTION",
|
68
|
+
type: "error",
|
69
|
+
sync_id: sync_config.sync_id,
|
70
|
+
sync_run_id: sync_config.sync_run_id
|
71
|
+
})
|
72
|
+
write_failure += 1
|
73
|
+
log_message_array << log_request_response("error", query, e.message)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
tracking_message(write_success, write_failure, log_message_array)
|
77
|
+
rescue StandardError => e
|
78
|
+
handle_exception(e, {
|
79
|
+
context: "AIS:DATA:STORE:RECORD:WRITE:EXCEPTION",
|
80
|
+
type: "error",
|
81
|
+
sync_id: sync_config.sync_id,
|
82
|
+
sync_run_id: sync_config.sync_run_id
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def query(connection, query)
|
89
|
+
connection.exec(query) do |result|
|
90
|
+
result.map do |row|
|
91
|
+
RecordMessage.new(data: row, emitted_at: Time.now.to_i).to_outhad_message
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_connection(connection_config)
|
97
|
+
raise "Unsupported Auth type" unless connection_config[:credentials][:auth_type] == "username/password"
|
98
|
+
|
99
|
+
PG.connect(
|
100
|
+
host: connection_config[:host],
|
101
|
+
dbname: connection_config[:database],
|
102
|
+
user: connection_config[:credentials][:username],
|
103
|
+
password: connection_config[:credentials][:password],
|
104
|
+
port: connection_config[:port]
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_streams(records)
|
109
|
+
group_by_table(records).map do |r|
|
110
|
+
Outhad::Integrations::Protocol::Stream.new(name: r[:tablename], action: StreamAction["fetch"], json_schema: convert_to_json_schema(r[:columns]))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def group_by_table(records)
|
115
|
+
records.group_by { |entry| entry["table_name"] }.map do |table_name, columns|
|
116
|
+
{
|
117
|
+
tablename: table_name,
|
118
|
+
columns: columns.map do |column|
|
119
|
+
{
|
120
|
+
column_name: column["column_name"],
|
121
|
+
type: column["data_type"],
|
122
|
+
optional: column["is_nullable"] == "YES"
|
123
|
+
}
|
124
|
+
end
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"name": "AISDataStore",
|
4
|
+
"title": "AIS Data Store",
|
5
|
+
"connector_type": "destination",
|
6
|
+
"category": "Database",
|
7
|
+
"documentation_url": "https://docs.squared.ai/guides/destinations/retl-destinations/database/ais_data_store",
|
8
|
+
"github_issue_label": "destination-ais-data-store",
|
9
|
+
"icon": "icon.svg",
|
10
|
+
"license": "MIT",
|
11
|
+
"release_stage": "alpha",
|
12
|
+
"support_level": "community",
|
13
|
+
"tags": ["language:ruby", "outhad"]
|
14
|
+
}
|
15
|
+
}
|