Skip to content

DBConnection

DB connection settings

Setting items

  • dbConnection - Configure settings to connect to mysql.

There are two ways to configure this: URL syntax and Object syntax.

URL syntax

URL syntax is set in the format mysql://user:pass@host:port/database.

module.exports = {
dbConnection: "mysql://user:pass@host:port/database",
};

Also, if you specify npx mysql-to-zod@latest mysql://user:pass@host:port/database at runtime, what you specify at runtime takes precedence over the settings described in the config file.

Object syntax

The Object syntax is set as follows. Since this library uses mysql2, the mysql2 settings are described as they are.

const options = {
dbConnection: {
host: "localhost",
user: "user",
password: "pass",
database: "database",
},
};
module.exports = options;

This is the same setting as the URL syntax described earlier.

If the password contains @, the URL syntax requires escaping, but the object syntax does not.