SQLite3 gem 中的类型转换有什么作用?

What does type translation in SQLite3 gem do?

type_translation = true 中的初始化方法未记录在 gem 的网站上。它有什么作用?

来自这个link:https://github.com/sparklemotion/sqlite3-ruby/blob/master/lib/sqlite3/database.rb

"...数据库 class 也提供类型转换服务,通过它 SQLite3 数据类型(都表示为字符串)可以转换成它们相应的类型(如模式中定义的用于他们的表)。这种转换仅在从数据库查询数据时发生——插入和更新仍然是无类型的...“

这也可能有帮助:https://sqlite.org/datatype3.html 因为它解释了 sqlite3 中如何处理数据类型。

答案可以通过examining the source code找到:

# Return the type translator employed by this database instance. Each
# database instance has its own type translator; this allows for different
# type handlers to be installed in each instance without affecting other
# instances. Furthermore, the translators are instantiated lazily, so that
# if a database does not use type translation, it will not be burdened by
# the overhead of a useless type translator. (See the Translator class.)

而当您查看 Translator class 时:

# The Translator class encapsulates the logic and callbacks necessary for
# converting string data to a value of some specified type. Every Database
# instance may have a Translator instance, in order to assist in type
# translation (Database#type_translation).

因此,当 type_translation = true 时,sqlite3 将使用该数据库的类型转换器来协助序列化数据类型之间的数据。