extralite 2.4 → 2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test-bundle.yml +30 -0
- data/.github/workflows/test.yml +2 -12
- data/CHANGELOG.md +49 -10
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/README.md +876 -217
- data/TODO.md +2 -3
- data/ext/extralite/changeset.c +463 -0
- data/ext/extralite/common.c +226 -19
- data/ext/extralite/database.c +339 -23
- data/ext/extralite/extconf-bundle.rb +10 -4
- data/ext/extralite/extconf.rb +31 -27
- data/ext/extralite/extralite.h +25 -5
- data/ext/extralite/extralite_ext.c +10 -0
- data/ext/extralite/iterator.c +8 -3
- data/ext/extralite/query.c +222 -22
- data/gemspec.rb +1 -1
- data/lib/extralite/version.rb +1 -1
- data/lib/extralite.rb +64 -8
- data/test/helper.rb +8 -0
- data/test/issue-54.rb +21 -0
- data/test/issue-59.rb +70 -0
- data/test/perf_ary.rb +14 -12
- data/test/perf_hash.rb +17 -15
- data/test/perf_hash_prepared.rb +58 -0
- data/test/test_changeset.rb +161 -0
- data/test/test_database.rb +672 -13
- data/test/test_query.rb +367 -2
- metadata +10 -5
- data/test/perf_prepared.rb +0 -64
data/test/test_query.rb
CHANGED
@@ -37,6 +37,11 @@ class QueryTest < MiniTest::Test
|
|
37
37
|
results = q.bind(foo: 'c').to_a_ary
|
38
38
|
|
39
39
|
assert_equal [['a', 'b', 'c']], results
|
40
|
+
|
41
|
+
# try again with the same parameters
|
42
|
+
results = q.to_a_ary
|
43
|
+
|
44
|
+
assert_equal [['a', 'b', 'c']], results
|
40
45
|
end
|
41
46
|
|
42
47
|
def test_query_next
|
@@ -478,7 +483,25 @@ class QueryTest < MiniTest::Test
|
|
478
483
|
assert_equal [[1, 2, 3], [4, 5, 6], [42, 8, 9]], @db.query_ary('select * from t order by z')
|
479
484
|
end
|
480
485
|
|
481
|
-
def
|
486
|
+
def test_query_execute_with_mixed_params
|
487
|
+
@db.execute 'delete from t'
|
488
|
+
q = @db.prepare('insert into t values (?, ?, ?)')
|
489
|
+
|
490
|
+
q.execute(1, [2], 3)
|
491
|
+
q.execute([4, 5], 6)
|
492
|
+
q.execute([7], 8, [9])
|
493
|
+
|
494
|
+
assert_equal [[1, 2, 3], [4, 5, 6], [7, 8, 9]], @db.query_ary('select * from t order by z')
|
495
|
+
end
|
496
|
+
|
497
|
+
def test_query_chverons
|
498
|
+
q = @db.prepare('update t set x = ? where z = ?')
|
499
|
+
assert_equal q, (q << [42, 9])
|
500
|
+
assert_equal [[1, 2, 3], [4, 5, 6], [42, 8, 9]], @db.query_ary('select * from t order by z')
|
501
|
+
end
|
502
|
+
|
503
|
+
|
504
|
+
def test_query_batch_execute
|
482
505
|
@db.query('create table foo (a, b, c)')
|
483
506
|
assert_equal [], @db.query('select * from foo')
|
484
507
|
|
@@ -488,7 +511,7 @@ class QueryTest < MiniTest::Test
|
|
488
511
|
]
|
489
512
|
|
490
513
|
p = @db.prepare('insert into foo values (?, ?, ?)')
|
491
|
-
changes = p.
|
514
|
+
changes = p.batch_execute(records)
|
492
515
|
|
493
516
|
assert_equal 2, changes
|
494
517
|
assert_equal [
|
@@ -497,6 +520,328 @@ class QueryTest < MiniTest::Test
|
|
497
520
|
], @db.query('select * from foo')
|
498
521
|
end
|
499
522
|
|
523
|
+
def test_query_batch_execute_with_each_interface
|
524
|
+
@db.query('create table foo (a)')
|
525
|
+
assert_equal [], @db.query('select * from foo')
|
526
|
+
|
527
|
+
p = @db.prepare('insert into foo values (?)')
|
528
|
+
changes = p.batch_execute(1..3)
|
529
|
+
|
530
|
+
assert_equal 3, changes
|
531
|
+
assert_equal [
|
532
|
+
{ a: 1 },
|
533
|
+
{ a: 2 },
|
534
|
+
{ a: 3 }
|
535
|
+
], @db.query('select * from foo')
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_query_batch_execute_with_proc
|
539
|
+
source = [42, 43, 44]
|
540
|
+
|
541
|
+
@db.query('create table foo (a)')
|
542
|
+
assert_equal [], @db.query('select * from foo')
|
543
|
+
|
544
|
+
p = @db.prepare('insert into foo values (?)')
|
545
|
+
pr = proc { source.shift }
|
546
|
+
changes = p.batch_execute(pr)
|
547
|
+
|
548
|
+
assert_equal 3, changes
|
549
|
+
assert_equal [
|
550
|
+
{ a: 42 },
|
551
|
+
{ a: 43 },
|
552
|
+
{ a: 44 }
|
553
|
+
], @db.query('select * from foo')
|
554
|
+
end
|
555
|
+
|
556
|
+
def test_query_batch_query_with_array
|
557
|
+
@db.query('create table foo (a integer primary key, b)')
|
558
|
+
assert_equal [], @db.query('select * from foo')
|
559
|
+
|
560
|
+
data = [5, 4, 3]
|
561
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
562
|
+
assert_equal [
|
563
|
+
[[1, 5]],
|
564
|
+
[[2, 4]],
|
565
|
+
[[3, 3]]
|
566
|
+
], results
|
567
|
+
|
568
|
+
q = @db.prepare('update foo set b = ? returning *')
|
569
|
+
|
570
|
+
results = q.batch_query([42, 43])
|
571
|
+
assert_equal [
|
572
|
+
[{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
|
573
|
+
[{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
|
574
|
+
], results
|
575
|
+
|
576
|
+
array = []
|
577
|
+
changes = q.batch_query([44, 45]) do |rows|
|
578
|
+
array << rows
|
579
|
+
end
|
580
|
+
assert_equal 6, changes
|
581
|
+
assert_equal [
|
582
|
+
[{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
|
583
|
+
[{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
|
584
|
+
], array
|
585
|
+
end
|
586
|
+
|
587
|
+
def test_query_batch_query_with_enumerable
|
588
|
+
@db.query('create table foo (a integer primary key, b)')
|
589
|
+
assert_equal [], @db.query('select * from foo')
|
590
|
+
|
591
|
+
data = [5, 4, 3]
|
592
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
593
|
+
assert_equal [
|
594
|
+
[[1, 5]],
|
595
|
+
[[2, 4]],
|
596
|
+
[[3, 3]]
|
597
|
+
], results
|
598
|
+
|
599
|
+
q = @db.prepare('update foo set b = ? returning *')
|
600
|
+
|
601
|
+
results = q.batch_query(42..43)
|
602
|
+
assert_equal [
|
603
|
+
[{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
|
604
|
+
[{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
|
605
|
+
], results
|
606
|
+
|
607
|
+
array = []
|
608
|
+
changes = q.batch_query(44..45) do |rows|
|
609
|
+
array << rows
|
610
|
+
end
|
611
|
+
assert_equal 6, changes
|
612
|
+
assert_equal [
|
613
|
+
[{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
|
614
|
+
[{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
|
615
|
+
], array
|
616
|
+
end
|
617
|
+
|
618
|
+
def parameter_source_proc(values)
|
619
|
+
proc { values.shift }
|
620
|
+
end
|
621
|
+
|
622
|
+
def test_query_batch_query_with_proc
|
623
|
+
@db.query('create table foo (a integer primary key, b)')
|
624
|
+
assert_equal [], @db.query('select * from foo')
|
625
|
+
|
626
|
+
data = [5, 4, 3]
|
627
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
628
|
+
assert_equal [
|
629
|
+
[[1, 5]],
|
630
|
+
[[2, 4]],
|
631
|
+
[[3, 3]]
|
632
|
+
], results
|
633
|
+
|
634
|
+
q = @db.prepare('update foo set b = ? returning *')
|
635
|
+
|
636
|
+
pr = parameter_source_proc([42, 43])
|
637
|
+
results = q.batch_query(pr)
|
638
|
+
assert_equal [
|
639
|
+
[{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
|
640
|
+
[{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
|
641
|
+
], results
|
642
|
+
|
643
|
+
array = []
|
644
|
+
pr = parameter_source_proc([44, 45])
|
645
|
+
changes = q.batch_query(pr) do |rows|
|
646
|
+
array << rows
|
647
|
+
end
|
648
|
+
assert_equal 6, changes
|
649
|
+
assert_equal [
|
650
|
+
[{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
|
651
|
+
[{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
|
652
|
+
], array
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_query_batch_query_ary_with_array
|
656
|
+
@db.query('create table foo (a integer primary key, b)')
|
657
|
+
assert_equal [], @db.query('select * from foo')
|
658
|
+
|
659
|
+
data = [5, 4, 3]
|
660
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
661
|
+
assert_equal [
|
662
|
+
[[1, 5]],
|
663
|
+
[[2, 4]],
|
664
|
+
[[3, 3]]
|
665
|
+
], results
|
666
|
+
|
667
|
+
q = @db.prepare('update foo set b = ? returning *')
|
668
|
+
|
669
|
+
results = q.batch_query_ary([42, 43])
|
670
|
+
assert_equal [
|
671
|
+
[[1, 42], [2, 42], [3, 42]],
|
672
|
+
[[1, 43], [2, 43], [3, 43]]
|
673
|
+
], results
|
674
|
+
|
675
|
+
array = []
|
676
|
+
changes = q.batch_query_ary([44, 45]) do |rows|
|
677
|
+
array << rows
|
678
|
+
end
|
679
|
+
assert_equal 6, changes
|
680
|
+
assert_equal [
|
681
|
+
[[1, 44], [2, 44], [3, 44]],
|
682
|
+
[[1, 45], [2, 45], [3, 45]]
|
683
|
+
], array
|
684
|
+
end
|
685
|
+
|
686
|
+
def test_query_batch_query_ary_with_enumerable
|
687
|
+
@db.query('create table foo (a integer primary key, b)')
|
688
|
+
assert_equal [], @db.query('select * from foo')
|
689
|
+
|
690
|
+
data = [5, 4, 3]
|
691
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
692
|
+
assert_equal [
|
693
|
+
[[1, 5]],
|
694
|
+
[[2, 4]],
|
695
|
+
[[3, 3]]
|
696
|
+
], results
|
697
|
+
|
698
|
+
q = @db.prepare('update foo set b = ? returning *')
|
699
|
+
|
700
|
+
results = q.batch_query_ary(42..43)
|
701
|
+
assert_equal [
|
702
|
+
[[1, 42], [2, 42], [3, 42]],
|
703
|
+
[[1, 43], [2, 43], [3, 43]]
|
704
|
+
], results
|
705
|
+
|
706
|
+
array = []
|
707
|
+
changes = q.batch_query_ary(44..45) do |rows|
|
708
|
+
array << rows
|
709
|
+
end
|
710
|
+
assert_equal 6, changes
|
711
|
+
assert_equal [
|
712
|
+
[[1, 44], [2, 44], [3, 44]],
|
713
|
+
[[1, 45], [2, 45], [3, 45]]
|
714
|
+
], array
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_query_batch_query_ary_with_proc
|
718
|
+
@db.query('create table foo (a integer primary key, b)')
|
719
|
+
assert_equal [], @db.query('select * from foo')
|
720
|
+
|
721
|
+
data = [5, 4, 3]
|
722
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
723
|
+
assert_equal [
|
724
|
+
[[1, 5]],
|
725
|
+
[[2, 4]],
|
726
|
+
[[3, 3]]
|
727
|
+
], results
|
728
|
+
|
729
|
+
q = @db.prepare('update foo set b = ? returning *')
|
730
|
+
|
731
|
+
pr = parameter_source_proc([42, 43])
|
732
|
+
results = q.batch_query_ary(pr)
|
733
|
+
assert_equal [
|
734
|
+
[[1, 42], [2, 42], [3, 42]],
|
735
|
+
[[1, 43], [2, 43], [3, 43]]
|
736
|
+
], results
|
737
|
+
|
738
|
+
array = []
|
739
|
+
pr = parameter_source_proc([44, 45])
|
740
|
+
changes = q.batch_query_ary(pr) do |rows|
|
741
|
+
array << rows
|
742
|
+
end
|
743
|
+
assert_equal 6, changes
|
744
|
+
assert_equal [
|
745
|
+
[[1, 44], [2, 44], [3, 44]],
|
746
|
+
[[1, 45], [2, 45], [3, 45]]
|
747
|
+
], array
|
748
|
+
end
|
749
|
+
|
750
|
+
def test_query_batch_query_single_column_with_array
|
751
|
+
@db.query('create table foo (a integer primary key, b)')
|
752
|
+
assert_equal [], @db.query('select * from foo')
|
753
|
+
|
754
|
+
data = [5, 4, 3]
|
755
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
756
|
+
assert_equal [
|
757
|
+
[[1, 5]],
|
758
|
+
[[2, 4]],
|
759
|
+
[[3, 3]]
|
760
|
+
], results
|
761
|
+
|
762
|
+
q = @db.prepare('update foo set b = ? returning b * 10 + a')
|
763
|
+
|
764
|
+
results = q.batch_query_single_column([42, 43])
|
765
|
+
assert_equal [
|
766
|
+
[421, 422, 423],
|
767
|
+
[431, 432, 433]
|
768
|
+
], results
|
769
|
+
|
770
|
+
array = []
|
771
|
+
changes = q.batch_query_single_column([44, 45]) do |rows|
|
772
|
+
array << rows
|
773
|
+
end
|
774
|
+
assert_equal 6, changes
|
775
|
+
assert_equal [
|
776
|
+
[441, 442, 443],
|
777
|
+
[451, 452, 453]
|
778
|
+
], array
|
779
|
+
end
|
780
|
+
|
781
|
+
def test_query_batch_query_single_column_with_enumerable
|
782
|
+
@db.query('create table foo (a integer primary key, b)')
|
783
|
+
assert_equal [], @db.query('select * from foo')
|
784
|
+
|
785
|
+
data = [5, 4, 3]
|
786
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
787
|
+
assert_equal [
|
788
|
+
[[1, 5]],
|
789
|
+
[[2, 4]],
|
790
|
+
[[3, 3]]
|
791
|
+
], results
|
792
|
+
|
793
|
+
q = @db.prepare('update foo set b = ? returning b * 10 + a')
|
794
|
+
|
795
|
+
results = q.batch_query_single_column(42..43)
|
796
|
+
assert_equal [
|
797
|
+
[421, 422, 423],
|
798
|
+
[431, 432, 433]
|
799
|
+
], results
|
800
|
+
|
801
|
+
array = []
|
802
|
+
changes = q.batch_query_single_column(44..45) do |rows|
|
803
|
+
array << rows
|
804
|
+
end
|
805
|
+
assert_equal 6, changes
|
806
|
+
assert_equal [
|
807
|
+
[441, 442, 443],
|
808
|
+
[451, 452, 453]
|
809
|
+
], array
|
810
|
+
end
|
811
|
+
|
812
|
+
def test_query_batch_query_single_column_with_proc
|
813
|
+
@db.query('create table foo (a integer primary key, b)')
|
814
|
+
assert_equal [], @db.query('select * from foo')
|
815
|
+
|
816
|
+
data = [5, 4, 3]
|
817
|
+
results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
|
818
|
+
assert_equal [
|
819
|
+
[[1, 5]],
|
820
|
+
[[2, 4]],
|
821
|
+
[[3, 3]]
|
822
|
+
], results
|
823
|
+
|
824
|
+
q = @db.prepare('update foo set b = ? returning b * 10 + a')
|
825
|
+
|
826
|
+
pr = parameter_source_proc([42, 43])
|
827
|
+
results = q.batch_query_single_column(pr)
|
828
|
+
assert_equal [
|
829
|
+
[421, 422, 423],
|
830
|
+
[431, 432, 433]
|
831
|
+
], results
|
832
|
+
|
833
|
+
array = []
|
834
|
+
pr = parameter_source_proc([44, 45])
|
835
|
+
changes = q.batch_query_single_column(pr) do |rows|
|
836
|
+
array << rows
|
837
|
+
end
|
838
|
+
assert_equal 6, changes
|
839
|
+
assert_equal [
|
840
|
+
[441, 442, 443],
|
841
|
+
[451, 452, 453]
|
842
|
+
], array
|
843
|
+
end
|
844
|
+
|
500
845
|
def test_query_status
|
501
846
|
assert_equal 0, @query.status(Extralite::SQLITE_STMTSTATUS_RUN)
|
502
847
|
@query.to_a
|
@@ -552,4 +897,24 @@ class QueryTest < MiniTest::Test
|
|
552
897
|
q = @db.prepare('select x from t')
|
553
898
|
assert_match /^\#\<Extralite::Query:0x[0-9a-f]+ #{q.sql.inspect}\>$/, q.inspect
|
554
899
|
end
|
900
|
+
|
901
|
+
def test_query_clone
|
902
|
+
q1 = @db.prepare('select x from t')
|
903
|
+
q2 = q1.clone
|
904
|
+
|
905
|
+
assert_kind_of Extralite::Query, q2
|
906
|
+
assert_equal @db, q2.database
|
907
|
+
assert_equal q1.sql, q2.sql
|
908
|
+
refute_equal q1, q2
|
909
|
+
end
|
910
|
+
|
911
|
+
def test_query_dup
|
912
|
+
q1 = @db.prepare('select x from t')
|
913
|
+
q2 = q1.dup
|
914
|
+
|
915
|
+
assert_kind_of Extralite::Query, q2
|
916
|
+
assert_equal @db, q2.database
|
917
|
+
assert_equal q1.sql, q2.sql
|
918
|
+
refute_equal q1, q2
|
919
|
+
end
|
555
920
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extralite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -90,6 +90,7 @@ extra_rdoc_files:
|
|
90
90
|
files:
|
91
91
|
- ".editorconfig"
|
92
92
|
- ".github/FUNDING.yml"
|
93
|
+
- ".github/workflows/test-bundle.yml"
|
93
94
|
- ".github/workflows/test.yml"
|
94
95
|
- ".gitignore"
|
95
96
|
- ".yardopts"
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- Rakefile
|
103
104
|
- TODO.md
|
104
105
|
- bin/update_sqlite_source
|
106
|
+
- ext/extralite/changeset.c
|
105
107
|
- ext/extralite/common.c
|
106
108
|
- ext/extralite/database.c
|
107
109
|
- ext/extralite/extconf-bundle.rb
|
@@ -123,10 +125,13 @@ files:
|
|
123
125
|
- test/fixtures/image.png
|
124
126
|
- test/helper.rb
|
125
127
|
- test/issue-38.rb
|
128
|
+
- test/issue-54.rb
|
129
|
+
- test/issue-59.rb
|
126
130
|
- test/perf_ary.rb
|
127
131
|
- test/perf_hash.rb
|
128
|
-
- test/
|
132
|
+
- test/perf_hash_prepared.rb
|
129
133
|
- test/run.rb
|
134
|
+
- test/test_changeset.rb
|
130
135
|
- test/test_database.rb
|
131
136
|
- test/test_extralite.rb
|
132
137
|
- test/test_iterator.rb
|
@@ -152,14 +157,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
157
|
requirements:
|
153
158
|
- - ">="
|
154
159
|
- !ruby/object:Gem::Version
|
155
|
-
version: '
|
160
|
+
version: '3.0'
|
156
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
162
|
requirements:
|
158
163
|
- - ">="
|
159
164
|
- !ruby/object:Gem::Version
|
160
165
|
version: '0'
|
161
166
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
167
|
+
rubygems_version: 3.5.3
|
163
168
|
signing_key:
|
164
169
|
specification_version: 4
|
165
170
|
summary: Extra-lightweight SQLite3 wrapper for Ruby
|
data/test/perf_prepared.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/inline'
|
4
|
-
|
5
|
-
gemfile do
|
6
|
-
source 'https://rubygems.org'
|
7
|
-
gem 'extralite', path: '..'
|
8
|
-
gem 'sqlite3'
|
9
|
-
gem 'benchmark-ips'
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'benchmark/ips'
|
13
|
-
require 'fileutils'
|
14
|
-
|
15
|
-
DB_PATH = '/tmp/extralite_sqlite3_perf.db'
|
16
|
-
|
17
|
-
def prepare_database(count)
|
18
|
-
FileUtils.rm(DB_PATH) rescue nil
|
19
|
-
db = Extralite::Database.new(DB_PATH)
|
20
|
-
db.query('create table foo ( a integer primary key, b text )')
|
21
|
-
db.query('begin')
|
22
|
-
count.times { db.query('insert into foo (b) values (?)', "hello#{rand(1000)}" )}
|
23
|
-
db.query('commit')
|
24
|
-
end
|
25
|
-
|
26
|
-
def sqlite3_prepare
|
27
|
-
db = SQLite3::Database.new(DB_PATH, :results_as_hash => true)
|
28
|
-
db.prepare('select * from foo')
|
29
|
-
end
|
30
|
-
|
31
|
-
def sqlite3_run(stmt, count)
|
32
|
-
# db = SQLite3::Database.new(DB_PATH, :results_as_hash => true)
|
33
|
-
results = stmt.execute.to_a
|
34
|
-
raise unless results.size == count
|
35
|
-
end
|
36
|
-
|
37
|
-
def extralite_prepare
|
38
|
-
db = Extralite::Database.new(DB_PATH)
|
39
|
-
db.prepare('select * from foo')
|
40
|
-
end
|
41
|
-
|
42
|
-
def extralite_run(query, count)
|
43
|
-
# db = Extralite::Database.new(DB_PATH)
|
44
|
-
results = query.to_a
|
45
|
-
raise unless results.size == count
|
46
|
-
end
|
47
|
-
|
48
|
-
[10, 1000, 100000].each do |c|
|
49
|
-
puts; puts; puts "Record count: #{c}"
|
50
|
-
|
51
|
-
prepare_database(c)
|
52
|
-
|
53
|
-
sqlite3_stmt = sqlite3_prepare
|
54
|
-
extralite_stmt = extralite_prepare
|
55
|
-
|
56
|
-
Benchmark.ips do |x|
|
57
|
-
x.config(:time => 3, :warmup => 1)
|
58
|
-
|
59
|
-
x.report("sqlite3") { sqlite3_run(sqlite3_stmt, c) }
|
60
|
-
x.report("extralite") { extralite_run(extralite_stmt, c) }
|
61
|
-
|
62
|
-
x.compare!
|
63
|
-
end
|
64
|
-
end
|