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.

构造一个新的 DatabaseSync 实例。

¥Constructs a new DatabaseSync instance.