new DatabaseSync(path[, options])


  • path <string> | <Buffer> | <URL> 数据库的路径。SQLite 数据库可以存储在文件中或完全 在内存中 中。要使用文件支持的数据库,路径应该是文件路径。要使用内存数据库,路径应该是特殊名称 ':memory:'

    ¥path <string> | <Buffer> | <URL> The path of the database. A SQLite database can be stored in a file or completely in memory. To use a file-backed database, the path should be a file path. To use an in-memory database, the path should be the special name ':memory:'.

  • options <Object> 数据库连接的配置选项。支持以下选项:

    ¥options <Object> Configuration options for the database connection. The following options are supported:

    • open <boolean> 如果是 true,则数据库由构造函数打开。当此值为 false 时,必须通过 open() 方法打开数据库。默认值:true

      ¥open <boolean> If true, the database is opened by the constructor. When this value is false, the database must be opened via the open() method. Default: true.

    • readOnly <boolean> 如果是 true,则数据库以只读模式打开。如果数据库不存在,则打开它将失败。默认值:false

      ¥readOnly <boolean> If true, the database is opened in read-only mode. If the database does not exist, opening it will fail. Default: false.

    • enableForeignKeyConstraints <boolean> 如果是 true,则启用外键约束。建议这样做,但可以禁用它以兼容旧数据库模式。使用 PRAGMA foreign_keys 打开数据库后,可以启用和禁用外键约束的实现。默认值:true

      ¥enableForeignKeyConstraints <boolean> If true, foreign key constraints are enabled. This is recommended but can be disabled for compatibility with legacy database schemas. The enforcement of foreign key constraints can be enabled and disabled after opening the database using PRAGMA foreign_keys. Default: true.

    • enableDoubleQuotedStringLiterals <boolean> 如果是 true,SQLite 将接受 双引号字符串字面量。不建议这样做,但可以启用它以兼容旧数据库模式。默认值:false

      ¥enableDoubleQuotedStringLiterals <boolean> If true, SQLite will accept double-quoted string literals. This is not recommended but can be enabled for compatibility with legacy database schemas. Default: false.

    • allowExtension <boolean> 如果 true,则启用 loadExtension SQL 函数和 loadExtension() 方法。你可以稍后调用 enableLoadExtension(false) 来禁用此功能。默认值:false

      ¥allowExtension <boolean> If true, the loadExtension SQL function and the loadExtension() method are enabled. You can call enableLoadExtension(false) later to disable this feature. Default: false.

    • timeout <number> 繁忙超时 以毫秒为单位。这是 SQLite 在返回错误之前等待数据库锁释放的最长时间。默认值:0

      ¥timeout <number> The busy timeout in milliseconds. This is the maximum amount of time that SQLite will wait for a database lock to be released before returning an error. Default: 0.

    • readBigInts <boolean> 如果是 true,整数字段将被读取为 JavaScript BigInt 值。如果是 false,整数字段将被读取为 JavaScript 数字。默认值:false

      ¥readBigInts <boolean> If true, integer fields are read as JavaScript BigInt values. If false, integer fields are read as JavaScript numbers. Default: false.

    • returnArrays <boolean> 如果是 true,查询结果将以数组而非对象的形式返回。默认值:false

      ¥returnArrays <boolean> If true, query results are returned as arrays instead of objects. Default: false.

    • allowBareNamedParameters <boolean> 如果是 true,则允许绑定不带前缀字符的命名参数(例如,使用 foo 而不是 :foo)。默认值:true

      ¥allowBareNamedParameters <boolean> If true, allows binding named parameters without the prefix character (e.g., foo instead of :foo). Default: true.

    • allowUnknownNamedParameters <boolean> 如果是 true,绑定时将忽略未知的命名参数。如果是 false,则会抛出未知命名参数的异常。默认值:false

      ¥allowUnknownNamedParameters <boolean> If true, unknown named parameters are ignored when binding. If false, an exception is thrown for unknown named parameters. Default: false.

    • defensive <boolean> 如果 true 为真,则启用防御标志。启用防御标志后,允许普通 SQL 故意损坏数据库文件的语言特性将被禁用。也可以使用 enableDefensive() 设置防御标志。默认值:false

      ¥defensive <boolean> If true, enables the defensive flag. When the defensive flag is enabled, language features that allow ordinary SQL to deliberately corrupt the database file are disabled. The defensive flag can also be set using enableDefensive(). Default: false.

构造一个新的 DatabaseSync 实例。

¥Constructs a new DatabaseSync instance.