Kevin Baker
Kevin Baker

Reputation: 1197

How do I add charset to Knex.js connection string?

I am using Knex.js for database connections. I would like to use a connection string instead of the connection object for connecting to a database and be able to specify the charset.

Example:

connection: 'mysql://root:[email protected]:3306/test-db'

NOT

connection: {
    host     : '127.0.0.1',
    user     : 'root',
    password : 'secret',
    database : 'test-db',
    charset  : 'utf8'
}

I have the connection string working.

Could someone explain how I would specify the charset in the Knex.js connection string?

Upvotes: 12

Views: 6839

Answers (1)

Δ O
Δ O

Reputation: 3710

Try:

connection: 'mysql://root:[email protected]:3306/test-db?charset=utf8mb4'

See connection string options as described here: https://github.com/mysqljs/mysql#connection-options

Upvotes: 6

Related Questions