Prisma1: TimeScaleDB connector

Created on 17 Jan 2018  ·  6Comments  ·  Source: prisma/prisma1

TimeScaleDB is a very cool Postgres Extension with time-series in mind – http://www.timescale.com

Should technically work out of the box with the Postgres connector. This is a placeholder request if that isn't the case, for any reason.

kinfeature areconnector

Most helpful comment

Hi there,

Any status regarding the TimescaleDB connector ?

Even though the PostgreSQL connector should work for Timescale out-of-the-box, what do you think are the changes or constraints to respect for hypertables with Prisma ?

Thanks.

All 6 comments

Hi there,

Any status regarding the TimescaleDB connector ?

Even though the PostgreSQL connector should work for Timescale out-of-the-box, what do you think are the changes or constraints to respect for hypertables with Prisma ?

Thanks.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

Hi,
Is timescaledb officially supported by prisma.
This thread does not conclude this topic.

TimescaleDB is actually an extension ontop of PostgreSQL. You can simply use the PostgreSQL connector. It is not too difficult to turn a Prisma generated table into a TimescaleDB hypertable. Here is the process:

Replace your PostgreSQL 10 docker image with: timescale/timescaledb:1.3.2-pg10

Then install TimescaleDB extension for your prisma database.

CREATE EXTENSION timescaledb; 

Run a Prisma migration that creates the table that stores your time series data

datamodel.prisma

type EventTrainer {
  id: Int! @id
  user: User
  time: DateTime! @createdAt
  meta: Json
}

TimescaleDB hypertables PRIMARY KEYs must include all dimensions that you want to partition by. So you have to drop the PRIMARY KEY Prisma generated during the data model migration, and then create one that includes the "time" dimension.

ALTER TABLE "default$default"."EventTrainer" DROP CONSTRAINT "EventTrainer_pkey";

ALTER TABLE "default$default"."EventTrainer" ADD CONSTRAINT "EventTrainer_pkey" PRIMARY KEY("id", "time");

Then convert the table into a hypertable

SELECT * FROM create_hypertable('"default$default"."EventTrainer"', 'time');
  • I am able to insert and query data using Prisma client/bindings just fine with the above hypertable.
  • The @createdAt decorator works and defaults to NOW() as expected.
  • Relation fields work

Nothing really seems to change from how you would normally use Prisma backed by vanilla PostgreSQL. Cheers my friends (-‿◦)

Thanks for the detailed explanation ZenSoftware!
It is fantastic and rest of the reply is coming from a different perspective and in no way disrespecting this approach and your help.

Yes, it is understandable that prisma and TimescaleDB have PostGreSQL in common. However there seems to be manual steps we need to do to make prisma to support TimescaleDB.

But if prisma officially supports TimescaleDB, this manual work will not be required.

Does prisma officially support TimescaleDB today or we need to come up approaches such as what is proposed above. If it does not support today, is there any plan in the near future?

👋🏽Ajay from TimescaleDB. If there are things we can to do help with this please let us know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jannone picture jannone  ·  3Comments

marktani picture marktani  ·  3Comments

schickling picture schickling  ·  3Comments

sorenbs picture sorenbs  ·  3Comments

marktani picture marktani  ·  3Comments