Skip to content

Commit

Permalink
feat(zmodel): add ulid() function (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Jan 8, 2025
1 parent 4d7275a commit 8e3b675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/schema/src/res/stdlib.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function uuid(version: Int?): String {
/**
* Generates a globally unique identifier based on the CUID spec.
*/
function cuid(): String {
function cuid(version: Int?): String {
} @@@expressionContext([DefaultValue])

/**
Expand All @@ -103,6 +103,12 @@ function cuid(): String {
function nanoid(length: Int?): String {
} @@@expressionContext([DefaultValue])

/**
* Generates an identifier based on the ulid spec.
*/
function ulid(): String {
} @@@expressionContext([DefaultValue])

/**
* Creates a sequence of integers in the underlying database and assign the incremented
* values to the ID values of the created records based on the sequence.
Expand Down
6 changes: 6 additions & 0 deletions packages/schema/tests/generator/prisma-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ describe('Prisma generator test', () => {
x String @default(nanoid())
y String @default(dbgenerated("gen_random_uuid()"))
z String @default(auth().id)
cuid String @default(cuid())
cuid2 String @default(cuid(2))
ulid String @default(ulid())
}
`);

Expand All @@ -183,6 +186,9 @@ describe('Prisma generator test', () => {
expect(content).toContain('@default(nanoid())');
expect(content).toContain('@default(dbgenerated("gen_random_uuid()"))');
expect(content).not.toContain('@default(auth().id)');
expect(content).toContain('@default(cuid())');
expect(content).toContain('@default(cuid(2))');
expect(content).toContain('@default(ulid())');
});

it('triple slash comments', async () => {
Expand Down

0 comments on commit 8e3b675

Please sign in to comment.