Open all2pie opened 2 years ago
TimescaleDB is just an extension of PostgreSQL which is already supported by TypeORM. Just follow the docs for PostgreSQL :+1:
@iam4x I know that and i have successfully connected to it but i do not use migrations so i need someway to create hyper-tables and also it would be good to have support for Timescale function, but i can do raw queries for that so that wont be an issue.
You can create hypertables in typeOrm:
import { MigrationInterface, QueryRunner } from 'typeorm';
export class TradesInit1640705305983 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE IF NOT EXISTS trades(
id serial,
mongo_id varchar(24) NOT NULL,
date TIMESTAMPTZ NOT NULL,
symbol varchar(30) NOT NULL,
price BIGINT NOT NULL,
amount BIGINT NOT NULL,
total_cost BIGINT NOT NULL
);`);
await queryRunner.query(
`CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;`,
);
await queryRunner.query(`SELECT create_hypertable('trades', 'date');`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE trades;`);
await queryRunner.query(`DROP EXTENSION timescaledb;`);
}
}
What I think we need is Hypertable options available at the Entity level.
Perhaps a simple option within Entity to mark as a hypertable... we'd also need to consider other options (Compression, Partitioning options etc).
Hyperfunction could be implemented as SQL with queryRunner for now - open to look at other implementation options.
@paltaa The matching entity for the trades
table would result in an error however:
ERROR: Entity "trades does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.
if I have a TypeORM entity I want to convert to a hyper table, there's a conflict of interest. TypeORM requires entities to have a primary key. Hyper tables can have a primary key, but that primary key must be part of the partition key: UNIQUE and PRIMARY constraints must include the partitioning key.
In my case, I must have an ID column annotated with PrimaryGeneratedColumn()
, while the hyper table is created on a timestamp field. This means I have to manually edit the generated migration in order to remove the primary key on ID, which might cause problems down the line, as the TypeORM entity states it has a primary key, but the created table doesn't.
I guess hypertables can only be resolved with custom queries.
I guess hypertables can only be resolved with custom queries.
Can you give me an example?
Some news about this issue/request?
Any updates? It would be great to add this to TypeORM
Any updates? @akindo is right about the primary key issue. Working with both TypORM and TimescaleDB seems like a serious hassle. It would be great if TypeORM could provide support for Hypertables.
any updates?
Feature Description
Please add support for Timescale db.
If it is already supported then please add it in the documentation.
Is is currently supported by sequelize:
Timescale Db
Relevant Database Driver
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?