kirei 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e3ce57ba0d801b5279632d302837a42195565c3daa66a2b5fbd6adb31f0176
4
- data.tar.gz: a3ba957501c2603cc8cfba22282ab0c281ccf8227f99fedad78af0c980f3edd3
3
+ metadata.gz: c1adc30a0abdfee8e565869c726e247ab07f3ab1cd535c2d7874182f501962a9
4
+ data.tar.gz: 533abff887e8aca8eda259ad66679b76b7d25d4236966a80fcf32dfafe18dcd2
5
5
  SHA512:
6
- metadata.gz: '078c2a848f346f8e25c0b9fcacc72d0d2e3b8f82620df2cffe4fee683e9d44aba43d3de635dd918449369617aa97362d2f66adba26d52c625565ff614eafe5d9'
7
- data.tar.gz: a57e28a79ff8fe6bf47060550d11521b14112f22e15088a365bf7965ef0caa1a9f56a80e55571477cea8807c63775513fdd04eb63bda355f677ce5aba95d032d
6
+ metadata.gz: ed22516b55aa7677b85dbf09e1f6f88822646574897e55831318eead12759f275e36394076be292be54d02f08223f78e827da3990d82871bcef6bd8d98a6f26c
7
+ data.tar.gz: 6aeb8fcc2cdf887da4824e1075c935f186f67d4639e01d6b099341a60e6c9ae7b6ce7ed30ad81ab1a40583152cf7006f4205c78d10b6aa775f45c345a53ff3f0
data/README.md CHANGED
@@ -13,7 +13,7 @@ TL;DR:
13
13
  * **zero magic**
14
14
  * **strict typing**
15
15
  * **very few low level dependencies**
16
- * ultra low memory footprint
16
+ * low memory footprint
17
17
  * high performance
18
18
  * simple to understand
19
19
 
@@ -85,12 +85,40 @@ module Kirei
85
85
  return unless App.config.db_extensions.include?(:pg_json)
86
86
 
87
87
  attributes.each_pair do |key, value|
88
- next unless value.is_a?(Hash) || value.is_a?(Array)
89
-
90
- attributes[key] = T.unsafe(Sequel).pg_jsonb_wrap(value)
88
+ if vector_column?(key.to_s)
89
+ attributes[key] = cast_to_vector(value)
90
+ elsif value.is_a?(Hash) || value.is_a?(Array)
91
+ attributes[key] = T.unsafe(Sequel).pg_jsonb_wrap(value)
92
+ end
91
93
  end
92
94
  end
93
95
 
96
+ #
97
+ # install the gem "pgvector" if you need to use vector columns
98
+ # also add `:pgvector` to the `App.config.db_extensions` array
99
+ # and enable the vector extension on the database.
100
+ #
101
+ sig { params(column_name: String).returns(T::Boolean) }
102
+ def vector_column?(column_name)
103
+ _col_name, col_info = T.let(
104
+ db.schema(table_name.to_sym).find { _1[0] == column_name.to_sym },
105
+ [Symbol, T::Hash[Symbol, T.untyped]],
106
+ )
107
+ col_info.fetch(:db_type).match?(/vector\(\d+\)/)
108
+ end
109
+
110
+ # New method to cast an array to a vector
111
+ sig { params(value: T.any(T::Array[Numeric], Sequel::SQL::Expression)).returns(Sequel::SQL::Expression) }
112
+ def cast_to_vector(value)
113
+ return value if value.is_a?(Sequel::SQL::Expression) || value.is_a?(Sequel::SQL::PlaceholderLiteralString)
114
+
115
+ Kernel.raise("'pg_array' extension is not enabled") unless db.extension(:pg_array)
116
+
117
+ pg_array = T.unsafe(Sequel).pg_array(value)
118
+
119
+ Sequel.lit("?::vector", pg_array)
120
+ end
121
+
94
122
  sig do
95
123
  override.params(
96
124
  hash: T::Hash[Symbol, T.untyped],
@@ -13,9 +13,9 @@ module Kirei
13
13
  String,
14
14
  Numeric,
15
15
  TCPSocket,
16
- Puma::Client,
16
+ ::Puma::Client,
17
17
  StringIO,
18
- Puma::Configuration,
18
+ ::Puma::Configuration,
19
19
  )
20
20
  ]
21
21
  end
@@ -10,7 +10,7 @@ module Kirei
10
10
  sig do
11
11
  type_parameters(:T)
12
12
  .params(
13
- class_name: T.untyped,
13
+ class_name: T.untyped, # @TODO(lud, 17.08.2024): replace all non-word characters with `.`?
14
14
  log_tags: T::Hash[String, T.untyped],
15
15
  block: T.proc.returns(T.type_parameter(:T)),
16
16
  ).returns(T.type_parameter(:T))
@@ -24,12 +24,7 @@ module Kirei
24
24
  stop = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
25
25
  latency_in_ms = stop - T.must(start)
26
26
 
27
- result = case service
28
- when Services::Result
29
- service.success? ? "success" : "failure"
30
- else
31
- "unknown"
32
- end
27
+ result = service_result(service)
33
28
 
34
29
  metric_tags = Logging::Metric.inject_defaults({ "service.result" => result })
35
30
  ::StatsD.measure(class_name, latency_in_ms, tags: metric_tags)
@@ -42,13 +37,31 @@ module Kirei
42
37
  }
43
38
  logtags.merge!(log_tags)
44
39
 
45
- Logging::Logger.call(level: Logging::Level::INFO, label: "Service Finished", meta: logtags)
40
+ Logging::Logger.call(level: log_level(result), label: "Service Finished", meta: logtags)
46
41
  end
47
42
 
48
43
  sig { params(proc: T.proc.returns(T.untyped)).returns(String) }
49
44
  private_class_method def self.source_location(proc)
50
45
  proc.source_location.join(":").gsub(App.root.to_s, "")
51
46
  end
47
+
48
+ sig { params(service: T.untyped).returns(String) }
49
+ def self.service_result(service)
50
+ case service
51
+ when Services::Result
52
+ service.success? ? "success" : "failure"
53
+ else
54
+ "unknown"
55
+ end
56
+ end
57
+
58
+ sig { params(result: String).returns(Logging::Level) }
59
+ private_class_method def self.log_level(result)
60
+ return Logging::Level::INFO if result == "success"
61
+ return Logging::Level::WARN if result == "failure"
62
+
63
+ Logging::Level::UNKNOWN
64
+ end
52
65
  end
53
66
  end
54
67
  end
data/lib/kirei/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Kirei
5
- VERSION = "0.4.1"
5
+ VERSION = "0.5.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kirei
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ludwig Reinmiedl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-10 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj