rubydb 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c076e3acf3d8cf15a98581eb92daafdbe2aba8a40805279c08c957aece8a601
4
- data.tar.gz: 36eeb2c1ea39757ee1c759af4f1abefea987ba28f0929642258f289c3196df66
3
+ metadata.gz: 569e9ce02867a64e165f0703b4c2f3135255666ac938b05bed690b846df8b9b7
4
+ data.tar.gz: 29d7e3cb03885093407d20c51e52bfb4bb17257b701b862b5070fff5bc8f9eb3
5
5
  SHA512:
6
- metadata.gz: 358853343b4781a04e72e1e9910ed4c8fe562f4e56a9d3b2c27bb6b962da78bc3eeabfca4efbfa3b83c8e8d0f3295b368701b38fbc2baab361109bfe173ca3b8
7
- data.tar.gz: a0a90a0cd04781b3dd35bbd94a46513debdf69195e09fadd677d21d27b005db874d048b8281d432f68350f86f21c64ceb39b24fa4ae17ee6903034782ca8dc4a
6
+ metadata.gz: 1a3a33eb843e173974500f6848e395d10b4004b30c05c5c14b3afc353d3eff1c128d3d4ed6c3779889384aa0554b08c28d3722a0bcd623dca8d3576454fcc467
7
+ data.tar.gz: 3784d9d65f06788ab7e6e934b46e9916e1cd3ce0fc86f30bc677fb9b23c0b0d6cc04223b6b7acdcf38122d9ce0972b71eff1681bb02e6c07c350bf73f06d0d3f
data/CHANGELOG.md CHANGED
@@ -23,6 +23,12 @@ All notable changes to RubyDB are documented here. Versions follow
23
23
  vacuum, maintenance, and release workflows.
24
24
  - Clarified the tested common SQLite-style profile and production limits.
25
25
 
26
+ ## 0.1.4 - 2026-09-09
27
+
28
+ - Returned logical generated primary-key values to ActiveRecord separately
29
+ from physical storage row identifiers, including after deletes.
30
+ - Preserved generated insert identifiers through the RubyDB result boundary.
31
+
26
32
  ## 0.1.3 - 2026-09-09
27
33
 
28
34
  - Normalized numeric MVCC visibility-map keys after restart to prevent mixed
@@ -249,7 +249,10 @@ module ActiveRecord
249
249
  log(sql, name) do
250
250
  params = bind_values(binds)
251
251
  result = @connection.execute(sql, params)
252
- id = result.row_id
252
+ # RubyDB keeps a physical row id for storage operations and a
253
+ # logical primary-key value for SQL/ActiveRecord. They can differ
254
+ # after deletes, so ActiveRecord must receive the logical id.
255
+ id = result.inserted_id || result.row_id
253
256
  ActiveRecord::Result.new([pk || "id"], id.nil? ? [] : [[id]])
254
257
  end
255
258
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rubydb-activerecord"
5
- spec.version = "0.1.1"
5
+ spec.version = "0.1.2"
6
6
  spec.authors = ["Aldane Hutchinson"]
7
7
  spec.email = ["aldanehutchinson5@gmail.com"]
8
8
 
@@ -89,6 +89,18 @@ RSpec.describe ActiveRecord::ConnectionAdapters::RubyDBAdapter do
89
89
  expect(settings_model.create!.reload.label).to eq("")
90
90
  end
91
91
 
92
+ it "returns the logical primary key after rows are deleted" do
93
+ connection = ActiveRecord::Base.connection
94
+ connection.execute("CREATE TABLE events (id INTEGER PRIMARY KEY, name VARCHAR(255) NOT NULL)")
95
+
96
+ events = Class.new(ActiveRecord::Base) { self.table_name = "events" }
97
+ events.create!(name: "first").destroy!
98
+ created = events.create!(name: "replacement")
99
+
100
+ expect(created.id).to eq(1)
101
+ expect(events.find(1).name).to eq("replacement")
102
+ end
103
+
92
104
  it "executes an ActiveRecord association join with qualified filtering" do
93
105
  stub_const("RubydbAccount", Class.new(ActiveRecord::Base) do
94
106
  self.table_name = "accounts"
@@ -258,8 +258,10 @@ module RubyDB
258
258
  row_count: inserted.sum { |result| result[:row_count] },
259
259
  affected_rows: inserted.sum { |result| result[:affected_rows] },
260
260
  row_ids: inserted.filter_map { |result| result[:row_id] },
261
- row_id: inserted.reverse_each.map { |result| result[:row_id] }.compact.first,
262
- message: "INSERT #{inserted.sum { |result| result[:affected_rows] }}"
261
+ row_id: inserted.reverse_each.map { |result| result[:row_id] }.compact.first,
262
+ inserted_ids: inserted.filter_map { |result| result[:inserted_id] },
263
+ inserted_id: inserted.reverse_each.map { |result| result[:inserted_id] }.compact.first,
264
+ message: "INSERT #{inserted.sum { |result| result[:affected_rows] }}"
263
265
  }
264
266
  rescue Exception
265
267
  @engine.rollback_transaction if implicit_transaction && @engine.in_transaction?
@@ -277,12 +279,18 @@ module RubyDB
277
279
 
278
280
  # Insert into engine
279
281
  table_columns = @engine.table_columns(table_name)
280
- row_id = @engine.insert_row(table_name, table_columns, row_data)
282
+ row_id = @engine.insert_row(table_name, table_columns, row_data)
283
+ primary_key = table_columns.find(&:primary_key?)
284
+ inserted_row = @engine.select_row(table_name, row_id, table_columns)
285
+ inserted_id = if primary_key && inserted_row
286
+ inserted_row[primary_key.name] || inserted_row[primary_key.name.to_sym]
287
+ end
281
288
 
282
289
  {
283
290
  row_count: 1,
284
291
  affected_rows: 1,
285
- row_id: row_id,
292
+ row_id: row_id,
293
+ inserted_id: inserted_id,
286
294
  message: "INSERT 1"
287
295
  }
288
296
  rescue DatabaseError => error
@@ -313,7 +321,8 @@ module RubyDB
313
321
  end
314
322
  row_id = existing[:_row_id] || existing["_row_id"]
315
323
  @engine.update_row(table_name, row_id, values)
316
- { row_count: 1, affected_rows: 1, row_id: row_id, message: "INSERT 0 UPDATE 1" }
324
+ inserted_id = target.map { |column| existing[column] || existing[column.to_sym] }.first
325
+ { row_count: 1, affected_rows: 1, row_id: row_id, inserted_id: inserted_id, message: "INSERT 0 UPDATE 1" }
317
326
  end
318
327
 
319
328
  def execute_update(plan)
@@ -7,7 +7,7 @@ module RubyDB
7
7
  include Enumerable
8
8
 
9
9
  attr_reader :columns, :rows, :row_count, :affected_rows
10
- attr_reader :command_tag, :statement_id, :row_id
10
+ attr_reader :command_tag, :statement_id, :row_id, :inserted_id
11
11
 
12
12
  def initialize(result)
13
13
  @columns = result[:columns] || result[:column_names] || []
@@ -16,7 +16,8 @@ module RubyDB
16
16
  @affected_rows = result[:affected_rows] || 0
17
17
  @command_tag = result[:command_tag] || "SELECT"
18
18
  @statement_id = result[:statement_id]
19
- @row_id = result[:row_id]
19
+ @row_id = result[:row_id]
20
+ @inserted_id = result[:inserted_id]
20
21
  @transaction_id = result[:transaction_id]
21
22
  @success = result[:success] != false
22
23
  @error = result[:error]
@@ -84,7 +85,9 @@ module RubyDB
84
85
  rows: @rows,
85
86
  row_count: @row_count,
86
87
  affected_rows: @affected_rows,
87
- command_tag: @command_tag,
88
+ command_tag: @command_tag,
89
+ row_id: @row_id,
90
+ inserted_id: @inserted_id,
88
91
  success: @success,
89
92
  error: @error,
90
93
  execution_time_ms: @execution_time
@@ -11,13 +11,13 @@ module RubyDB
11
11
  # - MAJOR: Incompatible API changes
12
12
  # - MINOR: Backwards-compatible new functionality
13
13
  # - PATCH: Backwards-compatible bug fixes
14
- VERSION = "0.1.3"
14
+ VERSION = "0.1.4"
15
15
 
16
16
  # Version components for easy access
17
17
  module Version
18
18
  MAJOR = 0
19
19
  MINOR = 1
20
- PATCH = 3
20
+ PATCH = 4
21
21
  PRE = nil # e.g., "alpha", "beta", "rc1"
22
22
 
23
23
  def self.to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldane Hutchinson