-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for partitioning (#1295)
- Loading branch information
1 parent
2b14645
commit f3013e0
Showing
7 changed files
with
234 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { | ||
PartitionColumnOptions, | ||
PartitionOptions, | ||
} from '../operations/tables'; | ||
import { toArray } from './toArray'; | ||
|
||
function formatPartitionColumn( | ||
column: string | PartitionColumnOptions, | ||
literal: (value: string) => string | ||
): string { | ||
if (typeof column === 'string') { | ||
return literal(column); | ||
} | ||
|
||
let formatted = literal(column.name); | ||
|
||
if (column.collate) { | ||
formatted += ` COLLATE ${column.collate}`; | ||
} | ||
|
||
if (column.opclass) { | ||
formatted += ` ${column.opclass}`; | ||
} | ||
|
||
return formatted; | ||
} | ||
|
||
// Helper function to format all partition columns | ||
export function formatPartitionColumns( | ||
partition: PartitionOptions, | ||
literal: (value: string) => string | ||
): string { | ||
const columns = toArray(partition.columns); | ||
return columns.map((col) => formatPartitionColumn(col, literal)).join(', '); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
exports.up = (pgm) => { | ||
pgm.createTable( | ||
't_partition', | ||
{ | ||
id: 'serial', | ||
string: { type: 'text', notNull: true }, | ||
created: { | ||
type: 'timestamp', | ||
notNull: true, | ||
default: pgm.func('current_timestamp'), | ||
}, | ||
}, | ||
{ | ||
constraints: { | ||
primaryKey: ['id', 'created'], | ||
}, | ||
partition: { | ||
strategy: 'RANGE', | ||
columns: 'created', | ||
}, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters