Skip to content

Commit

Permalink
Add binary uuid doc (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCavadenti committed Dec 7, 2021
1 parent 0e1e703 commit 50d75c4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
3 changes: 3 additions & 0 deletions components/Sidebar.jsx
Expand Up @@ -289,6 +289,9 @@ export default class Sidebar extends Component {
</a>
<ul className="toc_section">
<li>- <a href="#Utility-BatchInsert">Batch Insert</a></li>
<li>- <a href="#Utility-now">now</a></li>
<li>- <a href="#Utility-binToUuid">binToUuid</a></li>
<li>- <a href="#Utility-uuidToBin">uuidToBin</a></li>
</ul>

<a className="toc_title" href="#Interfaces">
Expand Down
4 changes: 2 additions & 2 deletions sections/schema.js
Expand Up @@ -709,8 +709,8 @@ export default [
{
type: "method",
method: "uuid",
example: "table.uuid(name)",
description: "Adds a uuid column - this uses the built-in uuid type in PostgreSQL, and falling back to a char(36) in other databases.",
example: "table.uuid(name, options=({[useBinaryUuid:boolean]})",
description: "Adds a uuid column - this uses the built-in uuid type in PostgreSQL, and falling back to a char(36) in other databases by default. If useBinaryUuid is true, binary(16) is used. See uuidToBin function to convert uuid in binary before inserting and binToUuid to convert binary uuid to uuid.",
children: [ ]
},
{
Expand Down
51 changes: 51 additions & 0 deletions sections/utility.js
Expand Up @@ -42,5 +42,56 @@ export default [
.then(function() { ... })
.catch(function(error) { ... });
`
},
{
type: "method",
method: "now",
example: "knex.fn.now(precision)",
description: "Return the current timestamp with a precision (optional)",
children: [
{
type: "code",
language: "js",
content: `
table.datetime('some_time', { precision: 6 }).defaultTo(knex.fn.now(6))
`
}
]
},
{
type: "method",
method: "binToUuid",
example: "knex.fn.binToUuid(binaryUuid)",
description: "Convert a binary uuid (binary(16)) to a string uuid (char(36))",
children: [
{
type: "code",
language: "js",
content: `
knex.schema.createTable('uuid_table', (t) => {
t.uuid('uuid_col_binary', { useBinaryUuid: true });
});
knex('uuid_table').insert({
uuid_col_binary: knex.fn.uuidToBin('3f06af63-a93c-11e4-9797-00505690773f'),
});
`
}
]
},
{
type: "method",
method: "uuidToBin",
example: "knex.fn.uuidToBin(uuid)",
description: "Convert a uuid (char(16)) to a binary uuid (binary(36))",
children: [
{
type: "code",
language: "js",
content: `
const res = await knex('uuid_table').select('uuid_col_binary');
knex.fn.binToUuid(res[0].uuid_col_binary)
`
}
]
}
]

0 comments on commit 50d75c4

Please sign in to comment.