Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info about microsecond precision on MySQL #99

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sections/installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ export default [
});
`
},
{
type: "info",
content: "Note: The database version can be specified when using the MySQL adapter to take advantage of increased timestamp precision that is available in versions 5.6.4 and newer. In older versions the microsecond information is lost when storing datetime or timestamp values. The default in Knex is to not use microsecond precision, but this will change in a future version so, if you are using a version of MySQL older than 5.6.4, it is strongly advised to include the version in your options."
},
{
type: "code",
language: "js",
content: `
var knex = require('knex')({
client: 'mysql',
version: '5.7',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
`
},
{
type: "text",
content: "You can also connect via an unix domain socket, which will ignore host and port."
Expand Down
11 changes: 7 additions & 4 deletions sections/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default [
method: "increments",
example: "table.increments(name)",
description: "Adds an auto incrementing column. In PostgreSQL this is a serial; in Amazon Redshift an integer identity(1,1). This will be used as the primary key for the table. Also available is a bigIncrements if you wish to add a bigint incrementing number (in PostgreSQL bigserial).",
children: [
children: [
{
type: 'code',
language: 'js',
Expand All @@ -240,7 +240,7 @@ export default [
table.foreign('author').references('userId').inTable('users');
});
`
}
}
]
},
{
Expand Down Expand Up @@ -317,18 +317,21 @@ export default [
type: "method",
method: "timestamp",
example: "table.timestamp(name, [standard])",
description: "Adds a timestamp column, defaults to timestamptz in PostgreSQL, unless true is passed as the second argument. For Example:",
description: "Adds a timestamp column, defaulting to timestamptz in PostgreSQL unless true is passed as the second argument. For Example:",
children: [{
type: 'code',
language: 'js',
content: `table.timestamp('created_at').defaultTo(knex.fn.now());`
}, {
type: 'text',
content: "Note that there's an issue of microsecond information being lost when stored on MySQL versions older than 5.6.4. If you need this kind of precision read the timestamps method documention below for further details."
}]
},
{
type: "method",
method: "timestamps",
example: "table.timestamps([useTimestamps], [defaultToNow])",
description: "Adds a created_at and updated_at column on the database, setting these each to dateTime types. When true is passed as the first argument a timestamp type is used. Both colums default to being not null and the current timestamp when true is passed as the second argument.",
description: "Adds created_at and updated_at columns on the database, setting each to dateTime types. When true is passed as the first argument a timestamp type is used instead. Both colums default to being not null and using the current timestamp when true is passed as the second argument. Note that on MySQL the timestamps will only have second precision by default because versions of MySQL Server older than 5.6.4 don't support storing microseconds. You can enable microsecond precision by specifying version 5.6 or greater in your settings when initializing Knex.",
children: [ ]
},
{
Expand Down