@@ -482,6 +482,113 @@ function tests.test_btree_stats_extended()
482482 print (" PASS: test_btree_stats_extended" )
483483end
484484
485+ function tests .test_clone_column_family ()
486+ local path = " ./test_db_clone_cf"
487+ cleanup_db (path )
488+
489+ local db = tidesdb .TidesDB .open (path )
490+ db :create_column_family (" source_cf" )
491+ local cf = db :get_column_family (" source_cf" )
492+
493+ -- Insert data into source
494+ local txn = db :begin_txn ()
495+ txn :put (cf , " key1" , " value1" )
496+ txn :put (cf , " key2" , " value2" )
497+ txn :commit ()
498+ txn :free ()
499+
500+ -- Clone column family
501+ db :clone_column_family (" source_cf" , " cloned_cf" )
502+
503+ -- Verify cloned column family exists
504+ local cloned_cf = db :get_column_family (" cloned_cf" )
505+ assert_true (cloned_cf ~= nil , " cloned column family should exist" )
506+
507+ -- Verify data is preserved in clone
508+ local read_txn = db :begin_txn ()
509+ local v1 = read_txn :get (cloned_cf , " key1" )
510+ local v2 = read_txn :get (cloned_cf , " key2" )
511+ assert_eq (v1 , " value1" , " cloned key1 should have correct value" )
512+ assert_eq (v2 , " value2" , " cloned key2 should have correct value" )
513+ read_txn :free ()
514+
515+ -- Verify source still works independently
516+ local src_txn = db :begin_txn ()
517+ local sv1 = src_txn :get (cf , " key1" )
518+ assert_eq (sv1 , " value1" , " source key1 should still exist" )
519+ src_txn :free ()
520+
521+ -- Verify modifications to clone don't affect source
522+ local write_txn = db :begin_txn ()
523+ write_txn :put (cloned_cf , " key3" , " value3" )
524+ write_txn :commit ()
525+ write_txn :free ()
526+
527+ local verify_txn = db :begin_txn ()
528+ local v3 = verify_txn :get (cloned_cf , " key3" )
529+ assert_eq (v3 , " value3" , " key3 should exist in clone" )
530+ local err = assert_error (function ()
531+ verify_txn :get (cf , " key3" )
532+ end , " key3 should not exist in source" )
533+ verify_txn :free ()
534+
535+ -- Verify cloning to existing name fails
536+ local clone_err = assert_error (function ()
537+ db :clone_column_family (" source_cf" , " cloned_cf" )
538+ end , " cloning to existing name should fail" )
539+
540+ db :drop_column_family (" source_cf" )
541+ db :drop_column_family (" cloned_cf" )
542+ db :close ()
543+ cleanup_db (path )
544+ print (" PASS: test_clone_column_family" )
545+ end
546+
547+ function tests .test_transaction_reset ()
548+ local path = " ./test_db_txn_reset"
549+ cleanup_db (path )
550+
551+ local db = tidesdb .TidesDB .open (path )
552+ db :create_column_family (" test_cf" )
553+ local cf = db :get_column_family (" test_cf" )
554+
555+ -- Begin transaction and do first batch of work
556+ local txn = db :begin_txn ()
557+ txn :put (cf , " key1" , " value1" )
558+ txn :commit ()
559+
560+ -- Reset transaction instead of free + begin
561+ txn :reset (tidesdb .IsolationLevel .READ_COMMITTED )
562+
563+ -- Second batch of work using the same transaction
564+ txn :put (cf , " key2" , " value2" )
565+ txn :commit ()
566+
567+ -- Reset again with different isolation level
568+ txn :reset (tidesdb .IsolationLevel .SERIALIZABLE )
569+
570+ -- Third batch
571+ txn :put (cf , " key3" , " value3" )
572+ txn :commit ()
573+
574+ txn :free ()
575+
576+ -- Verify all data was written
577+ local read_txn = db :begin_txn ()
578+ local v1 = read_txn :get (cf , " key1" )
579+ local v2 = read_txn :get (cf , " key2" )
580+ local v3 = read_txn :get (cf , " key3" )
581+ assert_eq (v1 , " value1" , " key1 should exist after reset" )
582+ assert_eq (v2 , " value2" , " key2 should exist after reset" )
583+ assert_eq (v3 , " value3" , " key3 should exist after reset" )
584+ read_txn :free ()
585+
586+ db :drop_column_family (" test_cf" )
587+ db :close ()
588+ cleanup_db (path )
589+ print (" PASS: test_transaction_reset" )
590+ end
591+
485592-- Run all tests
486593local function run_tests ()
487594 print (" Running TidesDB Lua tests..." )
0 commit comments