tina4ruby 3.13.14 → 3.13.16
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/lib/tina4/database.rb +12 -0
- data/lib/tina4/database_result.rb +15 -2
- data/lib/tina4/orm.rb +71 -10
- data/lib/tina4/version.rb +1 -1
- 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: b1cf076eb39a57f9c1cbdff22ff957b6abf2bc24ab245d603a88f4fdc780ab1f
|
|
4
|
+
data.tar.gz: 87a49969a5de07822dfeee8f4d6792dd0260409344519396e108ee45d8c68245
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a46003bec7bcaf5c5a4df7731a80b6d4e77b4eca9a9f467dcd061e94db7372192ba8751cf29d333518c49988224172adfab0a05bd16a14bc65fa2d2a5a209d98
|
|
7
|
+
data.tar.gz: ff0760e9a50bfe4f07dafc1c842060693a710de0ff5c3c9c5adfe606e858aee4219ea4e5bbdda600cd0252f89f83f749b619e426a884f0a6260e0c5552ce04bf
|
data/lib/tina4/database.rb
CHANGED
|
@@ -405,6 +405,18 @@ module Tina4
|
|
|
405
405
|
nil
|
|
406
406
|
end
|
|
407
407
|
|
|
408
|
+
# Return the normalised engine name for this connection.
|
|
409
|
+
#
|
|
410
|
+
# Cross-framework parity with Python/PHP/Node ``get_database_type()``.
|
|
411
|
+
# ORM.create_table needs this to emit engine-correct DDL (SERIAL vs
|
|
412
|
+
# AUTOINCREMENT, BOOLEAN vs INTEGER, TIMESTAMP vs DATETIME). Returns the
|
|
413
|
+
# resolved driver key ("postgres", "mysql", "mssql", "firebird",
|
|
414
|
+
# "sqlite", ...) — the same alias-normalised value used to pick the
|
|
415
|
+
# driver class, so callers don't have to re-parse the connection string.
|
|
416
|
+
def get_database_type
|
|
417
|
+
@driver_name
|
|
418
|
+
end
|
|
419
|
+
|
|
408
420
|
# Execute a write statement. Returns true/false for simple writes.
|
|
409
421
|
# Returns DatabaseResult if SQL contains RETURNING, CALL, EXEC, or SELECT.
|
|
410
422
|
def execute(sql, params = [])
|
|
@@ -39,8 +39,21 @@ module Tina4
|
|
|
39
39
|
@records.empty?
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
# Index / slice access into the result rows.
|
|
43
|
+
#
|
|
44
|
+
# ``result[0]`` is documented (book ch5 §4 "Index Access"). Delegating
|
|
45
|
+
# straight to the materialised rows means every Array subscript form
|
|
46
|
+
# works — ``result[0]``, ``result[-1]``, ``result[1, 2]`` and
|
|
47
|
+
# ``result[1..3]`` — and matches Python's ``DatabaseResult.__getitem__``,
|
|
48
|
+
# which forwards to its records list.
|
|
49
|
+
def [](*args)
|
|
50
|
+
@records[*args]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Implicit array coercion, so a DatabaseResult can be splatted and used
|
|
54
|
+
# anywhere an Array is expected (``a, b = result``, ``[*result]``).
|
|
55
|
+
def to_ary
|
|
56
|
+
@records.dup
|
|
44
57
|
end
|
|
45
58
|
|
|
46
59
|
def length
|
data/lib/tina4/orm.rb
CHANGED
|
@@ -306,13 +306,29 @@ module Tina4
|
|
|
306
306
|
def create_table
|
|
307
307
|
return true if db.table_exists?(table_name)
|
|
308
308
|
|
|
309
|
-
# v3.13.
|
|
310
|
-
#
|
|
311
|
-
#
|
|
312
|
-
#
|
|
313
|
-
#
|
|
314
|
-
#
|
|
309
|
+
# v3.13.16: engine-aware DDL. Ruby used to emit SQLite-only DDL on
|
|
310
|
+
# every driver — INTEGER for booleans, DATETIME for datetimes, and a
|
|
311
|
+
# raw AUTOINCREMENT keyword — then ignore db.execute()'s return value
|
|
312
|
+
# and report success. On PostgreSQL the CREATE blew up
|
|
313
|
+
# ("syntax error at or near AUTOINCREMENT"), db.execute() swallowed it
|
|
314
|
+
# into get_error() and returned false, yet create_table still returned
|
|
315
|
+
# true with no table created — a silent, misleading pass.
|
|
316
|
+
#
|
|
317
|
+
# The fix mirrors the Python reference (tina4_python.orm.model):
|
|
318
|
+
# • get_database_type() now exists on Database (it didn't before, so
|
|
319
|
+
# the v3.13.11 BooleanField check never actually fired on Ruby).
|
|
320
|
+
# • BooleanField → native BOOLEAN (PG/MySQL) / BIT (MSSQL) /
|
|
321
|
+
# INTEGER (sqlite, firebird) — both PG aliases are matched.
|
|
322
|
+
# • DateTimeField → TIMESTAMP on PG/Firebird (neither has a DATETIME
|
|
323
|
+
# type), DATETIME elsewhere.
|
|
324
|
+
# • boolean DEFAULT is engine-aware: TRUE/FALSE for a native BOOLEAN,
|
|
325
|
+
# 1/0 for INTEGER/BIT-backed bools.
|
|
326
|
+
# • AUTOINCREMENT is translated per engine via SQLTranslator
|
|
327
|
+
# (SERIAL on PG, AUTO_INCREMENT on MySQL, IDENTITY on MSSQL, dropped
|
|
328
|
+
# on Firebird) instead of being emitted raw.
|
|
329
|
+
# • return false (not true) when the DDL fails.
|
|
315
330
|
engine = (db.respond_to?(:get_database_type) ? db.get_database_type : "").to_s.downcase
|
|
331
|
+
|
|
316
332
|
bool_sql = case engine
|
|
317
333
|
when "postgres", "postgresql" then "BOOLEAN"
|
|
318
334
|
when "mysql" then "BOOLEAN" # alias for TINYINT(1)
|
|
@@ -320,6 +336,15 @@ module Tina4
|
|
|
320
336
|
else "INTEGER" # sqlite, firebird, odbc, anything else
|
|
321
337
|
end
|
|
322
338
|
|
|
339
|
+
# PostgreSQL and Firebird have no DATETIME type — CREATE TABLE fails
|
|
340
|
+
# with `type "datetime" does not exist`. Emit each engine's real
|
|
341
|
+
# timestamp type. (MySQL/MSSQL/SQLite keep DATETIME: valid there, and
|
|
342
|
+
# on MySQL it avoids TIMESTAMP's auto-update + 2038 surprises.)
|
|
343
|
+
datetime_sql = case engine
|
|
344
|
+
when "postgres", "postgresql", "firebird" then "TIMESTAMP"
|
|
345
|
+
else "DATETIME"
|
|
346
|
+
end
|
|
347
|
+
|
|
323
348
|
type_map = {
|
|
324
349
|
integer: "INTEGER",
|
|
325
350
|
string: "VARCHAR(255)",
|
|
@@ -328,7 +353,7 @@ module Tina4
|
|
|
328
353
|
decimal: "REAL",
|
|
329
354
|
boolean: bool_sql,
|
|
330
355
|
date: "DATE",
|
|
331
|
-
datetime:
|
|
356
|
+
datetime: datetime_sql,
|
|
332
357
|
timestamp: "TIMESTAMP",
|
|
333
358
|
blob: "BLOB",
|
|
334
359
|
json: "TEXT"
|
|
@@ -346,15 +371,29 @@ module Tina4
|
|
|
346
371
|
parts << "AUTOINCREMENT" if opts[:auto_increment]
|
|
347
372
|
parts << "NOT NULL" if !opts[:nullable] && !opts[:primary_key]
|
|
348
373
|
if opts[:default] && !opts[:auto_increment]
|
|
349
|
-
|
|
350
|
-
parts << "DEFAULT #{default_val}"
|
|
374
|
+
parts << "DEFAULT #{default_literal(opts[:default], opts[:type], bool_sql)}"
|
|
351
375
|
end
|
|
352
376
|
col_defs << parts.join(" ")
|
|
353
377
|
end
|
|
354
378
|
|
|
355
379
|
sql = "CREATE TABLE IF NOT EXISTS #{table_name} (#{col_defs.join(', ')})"
|
|
356
|
-
|
|
380
|
+
|
|
381
|
+
# Translate AUTOINCREMENT to the engine's auto-increment syntax
|
|
382
|
+
# (INTEGER PRIMARY KEY AUTOINCREMENT -> SERIAL PRIMARY KEY on PG, etc.).
|
|
383
|
+
# SQLTranslator keys off the -ql spelling for postgres.
|
|
384
|
+
translator_engine = %w[postgres postgresql].include?(engine) ? "postgresql" : engine
|
|
385
|
+
sql = SQLTranslator.auto_increment_syntax(sql, translator_engine)
|
|
386
|
+
|
|
387
|
+
# Don't claim success when the DDL failed. db.execute() swallows the
|
|
388
|
+
# driver error into get_error() and returns false, so a bad type (or
|
|
389
|
+
# any DDL error) used to leave create_table returning true while no
|
|
390
|
+
# table was actually created.
|
|
391
|
+
ok = db.execute(sql)
|
|
357
392
|
db.commit
|
|
393
|
+
if ok == false
|
|
394
|
+
Tina4::Log.error("create_table failed for #{table_name}: #{db.get_error}", { sql: sql })
|
|
395
|
+
return false
|
|
396
|
+
end
|
|
358
397
|
true
|
|
359
398
|
end
|
|
360
399
|
|
|
@@ -427,6 +466,28 @@ module Tina4
|
|
|
427
466
|
results = db.fetch(sql, filter.values)
|
|
428
467
|
results.map { |row| from_hash(row) }
|
|
429
468
|
end
|
|
469
|
+
|
|
470
|
+
# Render a column DEFAULT literal for create_table.
|
|
471
|
+
#
|
|
472
|
+
# Strings are quoted. Booleans are engine-aware: a native BOOLEAN
|
|
473
|
+
# column (PG/MySQL) needs TRUE/FALSE, while INTEGER- and BIT-backed
|
|
474
|
+
# bools (SQLite, Firebird, MSSQL) need 1/0 — `DEFAULT 0` on a PG
|
|
475
|
+
# BOOLEAN raises "default expression is of type integer". Everything
|
|
476
|
+
# else is emitted as-is.
|
|
477
|
+
def default_literal(value, type, bool_sql)
|
|
478
|
+
if value.is_a?(String)
|
|
479
|
+
"'#{value}'"
|
|
480
|
+
elsif value == true || value == false || type == :boolean
|
|
481
|
+
truthy = value == true || value == 1 || value == "1"
|
|
482
|
+
if bool_sql == "BOOLEAN"
|
|
483
|
+
truthy ? "TRUE" : "FALSE"
|
|
484
|
+
else
|
|
485
|
+
truthy ? "1" : "0"
|
|
486
|
+
end
|
|
487
|
+
else
|
|
488
|
+
value.to_s
|
|
489
|
+
end
|
|
490
|
+
end
|
|
430
491
|
end
|
|
431
492
|
|
|
432
493
|
def initialize(attributes = {})
|
data/lib/tina4/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tina4ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.13.
|
|
4
|
+
version: 3.13.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tina4 Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|