libsql-activerecord2 0.1.0 → 0.1.1
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49e46f2e7f9659cd1197b51d798967d40d8d729ab12c741b5441bb55e292312a
|
|
4
|
+
data.tar.gz: 20867f0eabcdea931e0b5304279e941daffa3228f689c7fa3f5766e5b29ee498
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1da507b20711799a25662259d78d0ca4c8d5f9dd77ec3e1d8f8d587c70ee33bc946e49545768c1e1051c65e0c1abf8099cb735143d8019b028383d64a4134a7
|
|
7
|
+
data.tar.gz: 7a96dd7d6f30afc0e29e04efcff22cd59a4496b9b9199abe047ed5e794d7be17a39adb4ad205c172dfc02e9fc62ffd4649754debb34f465b99ad1f4c419c2d06
|
|
@@ -83,6 +83,17 @@ module ActiveRecord
|
|
|
83
83
|
self.class.quote_table_name(name)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
# Convert ASCII-8BIT strings to UTF-8 so libsql2 treats them as TEXT
|
|
87
|
+
# rather than BLOB. Binary::Data (used for real BLOB values) is not
|
|
88
|
+
# a String, so it bypasses this branch and is handled by super.
|
|
89
|
+
def type_cast(value)
|
|
90
|
+
if value.is_a?(String) && value.encoding == Encoding::ASCII_8BIT
|
|
91
|
+
super(value.encode(Encoding::UTF_8))
|
|
92
|
+
else
|
|
93
|
+
super
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
86
97
|
def quoted_true = "1"
|
|
87
98
|
def quoted_false = "0"
|
|
88
99
|
def unquoted_true = 1
|
|
@@ -225,9 +236,11 @@ module ActiveRecord
|
|
|
225
236
|
# --- Schema introspection ---
|
|
226
237
|
|
|
227
238
|
def tables
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
with_raw_connection do |conn|
|
|
240
|
+
query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"
|
|
241
|
+
result = conn.query(query)
|
|
242
|
+
result.to_a.map { |row| row["name"] }
|
|
243
|
+
end
|
|
231
244
|
end
|
|
232
245
|
|
|
233
246
|
def table_exists?(table_name)
|
|
@@ -235,14 +248,18 @@ module ActiveRecord
|
|
|
235
248
|
end
|
|
236
249
|
|
|
237
250
|
def views
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
251
|
+
with_raw_connection do |conn|
|
|
252
|
+
query = "SELECT name FROM sqlite_master WHERE type='view' AND name NOT LIKE 'sqlite_%' ORDER BY name"
|
|
253
|
+
result = conn.query(query)
|
|
254
|
+
result.to_a.map { |row| row["name"] }
|
|
255
|
+
end
|
|
241
256
|
end
|
|
242
257
|
|
|
243
258
|
def column_definitions(table_name)
|
|
244
|
-
|
|
245
|
-
|
|
259
|
+
with_raw_connection do |conn|
|
|
260
|
+
result = conn.query("PRAGMA table_info(#{quote_table_name(table_name)})")
|
|
261
|
+
result.to_a
|
|
262
|
+
end
|
|
246
263
|
end
|
|
247
264
|
|
|
248
265
|
def new_column_from_field(_table_name, field, _definitions)
|
|
@@ -263,28 +280,32 @@ module ActiveRecord
|
|
|
263
280
|
end
|
|
264
281
|
|
|
265
282
|
def primary_keys(table_name)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
283
|
+
with_raw_connection do |conn|
|
|
284
|
+
result = conn.query("PRAGMA table_info(#{quote_table_name(table_name)})")
|
|
285
|
+
result.to_a
|
|
286
|
+
.select { |row| row["pk"].to_i.positive? }
|
|
287
|
+
.sort_by { |row| row["pk"].to_i }
|
|
288
|
+
.map { |row| row["name"] }
|
|
289
|
+
end
|
|
271
290
|
end
|
|
272
291
|
|
|
273
292
|
def indexes(table_name)
|
|
274
|
-
|
|
293
|
+
with_raw_connection do |conn|
|
|
294
|
+
index_list = conn.query("PRAGMA index_list(#{quote_table_name(table_name)})").to_a
|
|
275
295
|
|
|
276
|
-
|
|
277
|
-
|
|
296
|
+
index_list.filter_map do |idx|
|
|
297
|
+
next if idx["name"].start_with?("sqlite_")
|
|
278
298
|
|
|
279
|
-
|
|
280
|
-
|
|
299
|
+
columns = conn.query("PRAGMA index_info(#{quote_table_name(idx['name'])})").to_a
|
|
300
|
+
column_names = columns.sort_by { |c| c["seqno"].to_i }.map { |c| c["name"] }
|
|
281
301
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
302
|
+
IndexDefinition.new(
|
|
303
|
+
table_name,
|
|
304
|
+
idx["name"],
|
|
305
|
+
idx["unique"].to_i != 0,
|
|
306
|
+
column_names
|
|
307
|
+
)
|
|
308
|
+
end
|
|
288
309
|
end
|
|
289
310
|
end
|
|
290
311
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: libsql-activerecord2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Speria
|
|
@@ -46,6 +46,7 @@ files:
|
|
|
46
46
|
- LICENSE
|
|
47
47
|
- README.md
|
|
48
48
|
- lib/active_record/connection_adapters/libsql_adapter.rb
|
|
49
|
+
- lib/libsql-activerecord2.rb
|
|
49
50
|
- lib/libsql_activerecord.rb
|
|
50
51
|
- lib/libsql_activerecord/railtie.rb
|
|
51
52
|
- lib/libsql_activerecord/version.rb
|
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
69
|
- !ruby/object:Gem::Version
|
|
69
70
|
version: '0'
|
|
70
71
|
requirements: []
|
|
71
|
-
rubygems_version: 4.0.
|
|
72
|
+
rubygems_version: 4.0.6
|
|
72
73
|
specification_version: 4
|
|
73
74
|
summary: ActiveRecord adapter for libSQL / Turso
|
|
74
75
|
test_files: []
|