pglite 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28fd8d692265b7dc6a3331c0fa49ebf61474f91bda661f74349ed6104064b793
4
- data.tar.gz: d9ecb1b34511a4916429df30a270cf3951bf2b2d2eaeaa9ed559bc7a9752db4a
3
+ metadata.gz: 609fd58663c3fe74ac615524bf32871d8f50d71eda095d4845cdaa54c7320d5d
4
+ data.tar.gz: 44bd42c1c7e83ba12ca9474b2ac45e0ba43e1530a3cdb6bdd8004bbdaa5288a2
5
5
  SHA512:
6
- metadata.gz: 96c5d925d419b87b202f55f47e0874fe28041c6c0f8fc9747d4f947d65bd14017a628a2d54f15321cfe1f5e6059349ab83a81f6ec78a1eca28f19b8afe771013
7
- data.tar.gz: e9eb1d32b2edd46b41732d5aa475f50e39f8ddd9251af6c5aafa00d19041cefcd1c5f792859ef8c2dc039b34396acb8b7f4b0fb0be78d297a565743f79fedf9b
6
+ metadata.gz: 65a0e5e17832735317ebf54cc1c7bb93b815dff2bb9b8efc534c3cf281c139012ce1e43c2b152d49d5f1e12c2f191218023433583905c2ce8408c2bc06d424d0
7
+ data.tar.gz: b0365fdee8d300d6bc9c4446feb32a4ed70e66b4466ee56c1ac95773647406af899b9492ddc99ddfe3e6ef7446dcd46b8bd62693e9f649140648a16a2c4e61cc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.2.0 (2026-07-17)
6
+
7
+ - Add async interface (for Rails 8.2+).
8
+
5
9
  - Add `#parameter_status` stub to Connection.
6
10
 
7
11
  It's used by Rails 8.2-dev.
@@ -10,6 +10,7 @@ module PGlite
10
10
  def initialize(conn_params = {})
11
11
  @mount_path = conn_params[:mount_path] || File.join(Dir.pwd, "tmp", "pglite")
12
12
  @prepared_statements_map = {}
13
+ @closed = false
13
14
  PGlite.install!(mount_path)
14
15
  rescue => e
15
16
  raise PG::Error, e.message
@@ -19,13 +20,18 @@ module PGlite
19
20
  # make no-op for now
20
21
  end
21
22
 
22
- def finished? = true
23
+ def finished? = @closed
23
24
 
24
25
  def transaction_status
25
26
  PG::PQTRANS_IDLE
26
27
  end
27
28
 
28
- def parameter_status(_) = nil
29
+ def parameter_status(name)
30
+ # Rails can query for the current time zone
31
+ return "UTC" if name.to_s.casecmp?("timezone")
32
+
33
+ nil
34
+ end
29
35
 
30
36
  def escape(str) = str
31
37
 
@@ -67,6 +73,41 @@ module PGlite
67
73
  @prepared_statements_map[name] = sql
68
74
  end
69
75
 
76
+ # ==== Async interface for Active Record 8.2+ ===
77
+ def send_query(sql)
78
+ @pending_result = raw_query(sql, [])
79
+ nil
80
+ end
81
+
82
+ def send_query_params(sql, params)
83
+ @pending_result = raw_query(sql, params)
84
+ nil
85
+ end
86
+
87
+ def send_query_prepared(name, params)
88
+ @pending_result = exec_prepared(name, params)
89
+ nil
90
+ end
91
+
92
+ def send_prepare(name, sql, param_types = nil)
93
+ prepare(name, sql, param_types)
94
+ @pending_result = nil
95
+ nil
96
+ end
97
+
98
+ def get_result
99
+ result, @pending_result = @pending_result, nil
100
+ result
101
+ end
102
+
103
+ def discard_results
104
+ @pending_result = nil
105
+ end
106
+
107
+ def set_notice_receiver(&block)
108
+ nil
109
+ end
110
+
70
111
  def get_last_result
71
112
  @last_result
72
113
  end
@@ -82,5 +123,12 @@ module PGlite
82
123
  _1[1].to_i * 10_000 + _1[2].to_i
83
124
  end
84
125
  end
126
+
127
+ def close
128
+ @closed = true
129
+ nil
130
+ end
131
+
132
+ def status = PG::CONNECTION_OK
85
133
  end
86
134
  end
data/lib/pglite/pg.rb CHANGED
@@ -13,6 +13,11 @@ module PG
13
13
  PQTRANS_INTRANS = 2 # (idle, within transaction block)
14
14
  PQTRANS_INERROR = 3 # (idle, within failed transaction)
15
15
  PQTRANS_UNKNOWN = 4 # (cannot determine status)
16
+ CONNECTION_OK = 0
17
+
18
+ PGRES_COMMAND_OK = 1 # (successful completion of a command returning no data)
19
+ PGRES_TUPLES_OK = 2 # (successful completion of a command returning data)
20
+ PGRES_FATAL_ERROR = 7 # (a fatal error occurred)
16
21
 
17
22
  class Error < StandardError; end
18
23
  class ConnectionBad < Error; end
data/lib/pglite/result.rb CHANGED
@@ -25,6 +25,13 @@ module PGlite
25
25
 
26
26
  def ntuples = res.row_count
27
27
 
28
+ # Rails' get_result loop compares against PG::PGRES_FATAL_ERROR; pglite
29
+ # raises PG::Error at query time, so any result reaching here is non-fatal.
30
+ def result_status = PG::PGRES_TUPLES_OK
31
+
32
+ # Rails calls result.check to raise on server errors; already handled upstream.
33
+ def check = self
34
+
28
35
  def clear
29
36
  end
30
37
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PGlite # :nodoc:
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pglite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev