carray-io-sqlite3 0.9.2 → 0.9.3
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 +4 -4
- data/carray-io-sqlite3.gemspec +1 -1
- data/lib/carray-io-sqlite3/core.rb +28 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1314c190f90f50800ec969287e33214b64c7492ae4541027c92e6bb95dba19f5
|
4
|
+
data.tar.gz: 7d9cdd018be9407fe1d5c8ff78d0c7529551478a369b15f5a8c48daf2f7dbe36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e26cd252361633fa52d7ee0c2e8e5b9039783378e70bb6a913c47971b41ecfd0f3a81f7886303dd125575f30d6da0248b3c097fdccf37f05f7521e75cade3d3
|
7
|
+
data.tar.gz: 2ee64698ac7e9e4e44e2a64bb535376573aa9f200cb188991c8181b821f4ed8578f29a65042861b8109418c9a5d70f147cd816f0e3bc74732e74842ae46f3ab8
|
data/carray-io-sqlite3.gemspec
CHANGED
@@ -23,12 +23,12 @@ class CArray
|
|
23
23
|
raise "invalid 1st arg"
|
24
24
|
end
|
25
25
|
table = table.to_ca
|
26
|
-
table.extend(
|
26
|
+
table.extend(CArray::TableMethods)
|
27
27
|
table.column_names = names
|
28
28
|
return table
|
29
29
|
end
|
30
30
|
|
31
|
-
def to_sqlite3 (database: nil, table:, datatype: "numeric", schema: nil, transaction: true)
|
31
|
+
def to_sqlite3 (database: nil, table:, datatype: "numeric", schema: nil, transaction: true, primary_key: nil)
|
32
32
|
unless rank <= 2
|
33
33
|
raise "to_sqlite3 is valid only for 2-dim array (table)"
|
34
34
|
end
|
@@ -56,28 +56,40 @@ class CArray
|
|
56
56
|
if schema
|
57
57
|
database.execute "create table if not exists #{table} (" + schema + ")"
|
58
58
|
else
|
59
|
-
|
59
|
+
constraints = []
|
60
|
+
case primary_key
|
61
|
+
when String
|
62
|
+
constraints << "primary key (#{primary_key})"
|
63
|
+
when Array
|
64
|
+
constraints << "primary key (#{primary_key.join(",")})"
|
65
|
+
end
|
66
|
+
entries = vars.map{|s| s + " " + datatype } + constraints
|
67
|
+
database.execute "create table if not exists #{table} (" + entries.join(",") + ")"
|
60
68
|
end
|
61
69
|
|
62
70
|
insert = database.prepare %{ insert or replace into #{table} values (#{(["?"]*vars.size).join(",")}) }
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
insert.execute [self[i]]
|
67
|
-
end
|
68
|
-
else
|
69
|
-
begin
|
71
|
+
begin
|
72
|
+
database.transaction if transaction
|
73
|
+
if rank == 1
|
70
74
|
dim0.times do |i|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
insert.execute [self[i]]
|
76
|
+
end
|
77
|
+
else
|
78
|
+
out = self.object.unmask("null")
|
79
|
+
begin
|
80
|
+
dim0.times do |i|
|
81
|
+
begin
|
82
|
+
insert.execute out[i,nil].to_a
|
83
|
+
rescue
|
84
|
+
puts out[i,nil].to_a.inspect
|
85
|
+
raise $!
|
86
|
+
end
|
76
87
|
end
|
77
88
|
end
|
78
89
|
end
|
90
|
+
ensure
|
91
|
+
database.commit if transaction
|
79
92
|
end
|
80
|
-
database.commit if transaction
|
81
93
|
insert.close
|
82
94
|
return database
|
83
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carray-io-sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroki Motoyoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carray
|