diff --git a/Gemfile.lock b/Gemfile.lock index 997fb6a..d59a56f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM erubi (1.13.0) ethon (0.16.0) ffi (>= 1.15.0) - factbase (0.3.0) + factbase (0.4.0) backtrace (> 0) decoor (> 0) json (~> 2.7) diff --git a/lib/fbe/fb.rb b/lib/fbe/fb.rb index f7a730c..6a455c8 100644 --- a/lib/fbe/fb.rb +++ b/lib/fbe/fb.rb @@ -40,11 +40,12 @@ def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog) uid: '_id' ) fbe = - Factbase::Pre.new(fbe) do |f| - max = fbe.query('(eq _id (max _id))').each.to_a.first + Factbase::Pre.new(fbe) do |f, fbt| + max = fbt.query('(eq _id (max _id))').each.to_a.first f._id = (max.nil? ? 0 : max._id) + 1 f._time = Time.now f._version = "#{Factbase::VERSION}/#{Judges::VERSION}/#{options.action_version}" + f._job = options.job_id unless options.job_id.nil? end Factbase::Looged.new(fbe, loog) end diff --git a/test/fbe/test_fb.rb b/test/fbe/test_fb.rb index 46aad1a..3cca4bd 100644 --- a/test/fbe/test_fb.rb +++ b/test/fbe/test_fb.rb @@ -46,4 +46,31 @@ def test_simple stdout = $loog.to_s assert(stdout.include?('Inserted new fact #1'), stdout) end + + def test_increment_id_in_transaction + $fb = Factbase.new + $global = {} + $options = Judges::Options.new + $loog = Loog::Buffer.new + Fbe.fb.txn do |fbt| + fbt.insert + fbt.insert + end + arr = Fbe.fb.query('(always)').each.to_a + assert_equal(1, arr[0]._id) + assert_equal(2, arr[1]._id) + end + + def test_adds_meta_properties + $fb = Factbase.new + $global = {} + $options = Judges::Options.new('JOB_ID' => 42) + $loog = Loog::Buffer.new + Fbe.fb.insert + f = Fbe.fb.query('(always)').each.to_a.first + assert(!f._id.nil?) + assert(!f._time.nil?) + assert(!f._version.nil?) + assert(!f._job.nil?) + end end