question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to define UUID generated type within a table interface

See original GitHub issue

I am unsure if this is supported or if my implementation is incorrect. But I am looking to achieve something like this.

model

interface User {
  id: Generated<UUID>;
}

DB write schema

.addColumn("id", "uuid", (col) =>
      col.primaryKey().defaultTo(sql`gen_random_uuid()`)
    )

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
koskimascommented, Oct 15, 2022

The pg driver returns UUID fields as strings --> you need to use string as the type in the interface.

1reaction
igalklebanovcommented, Oct 15, 2022

It is supported and tested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the UUID data type - Oracle Help Center
A table column can be declared as having UUID type in a CREATE TABLE statement. The UUID data ... This UUID column can...
Read more >
How to use a JVM or database auto-generated UUID identifier ...
Learn how to use an auto-generated UUID entity identifier with JPA and Hibernate. The UUID can be either generated in the JVM or...
Read more >
The Ultimate Guide on Client-Generated IDs in JPA Entities
UUID generation – is a well-known and widely used approach for ID generation in distributed applications. This datatype is supported by standard ...
Read more >
Generate UUID values by default for each row on column of ...
In SQL. You can use built-in function RANDOM_UUID() : create table test(id int primary key, data uuid default random_uuid()); insert into ...
Read more >
PostgreSQL - UUID Data Type - GeeksforGeeks
For generating a UUID values based on the blend of computer's MAC address, present timestamp, and a random value, the uuid_generate_v1() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found