-
-
Save mizchi/86902c2b287cfc11cb7a2799980b1ca3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| prisma:info Starting a sqlite pool with 17 connections. | |
| prisma:info Started http server on http+unix:///private/tmp/prisma-789c342c854e2e3b622ab519.sock | |
| prisma:query BEGIN | |
| prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE `dev`.`User`.`name` = ? LIMIT ? OFFSET ? | |
| prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE `dev`.`User`.`name` = ? | |
| prisma:query UPDATE `dev`.`User` SET `name` = ? WHERE `dev`.`User`.`id` IN (?) | |
| prisma:query SELECT `dev`.`User`.`id`, `dev`.`User`.`name` FROM `dev`.`User` WHERE `dev`.`User`.`id` = ? LIMIT ? OFFSET ? | |
| prisma:query COMMIT | |
| prisma:query BEGIN | |
| prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE `dev`.`User`.`id` = ? LIMIT ? OFFSET ? | |
| prisma:query INSERT INTO `dev`.`Snippet` (`title`, `id`, `authorId`) VALUES (?,?,?) | |
| prisma:query SELECT `dev`.`ChunkOwnership`.`snippetId`, `dev`.`ChunkOwnership`.`filepath` FROM `dev`.`ChunkOwnership` WHERE (`dev`.`ChunkOwnership`.`snippetId` = ? AND `dev`.`ChunkOwnership`.`filepath` = ?) LIMIT ? OFFSET ? | |
| prisma:query SELECT `dev`.`Chunk`.`hash` FROM `dev`.`Chunk` WHERE `dev`.`Chunk`.`hash` = ? LIMIT ? OFFSET ? | |
| prisma:query INSERT INTO `dev`.`ChunkOwnership` (`filepath`, `hash`, `snippetId`) VALUES (?,?,?) | |
| prisma:query SELECT `dev`.`ChunkOwnership`.`snippetId`, `dev`.`ChunkOwnership`.`filepath` FROM `dev`.`ChunkOwnership` WHERE (`dev`.`ChunkOwnership`.`snippetId` = ? AND `dev`.`ChunkOwnership`.`filepath` = ?) LIMIT ? OFFSET ? | |
| prisma:query SELECT `dev`.`Chunk`.`hash` FROM `dev`.`Chunk` WHERE `dev`.`Chunk`.`hash` = ? LIMIT ? OFFSET ? | |
| prisma:query INSERT INTO `dev`.`ChunkOwnership` (`filepath`, `hash`, `snippetId`) VALUES (?,?,?) | |
| prisma:query SELECT `dev`.`Snippet`.`id`, `dev`.`Snippet`.`title`, `dev`.`Snippet`.`authorId` FROM `dev`.`Snippet` WHERE `dev`.`Snippet`.`id` = ? LIMIT ? OFFSET ? | |
| prisma:query COMMIT | |
| prisma:query SELECT `dev`.`Snippet`.`id`, `dev`.`Snippet`.`title`, `dev`.`Snippet`.`authorId` FROM `dev`.`Snippet` WHERE `dev`.`Snippet`.`id` = ? LIMIT ? OFFSET ? | |
| prisma:query SELECT `dev`.`ChunkOwnership`.`snippetId`, `dev`.`ChunkOwnership`.`filepath`, `dev`.`ChunkOwnership`.`hash` FROM `dev`.`ChunkOwnership` WHERE `dev`.`ChunkOwnership`.`snippetId` IN (?) LIMIT ? OFFSET ? | |
| prisma:query SELECT `dev`.`Chunk`.`hash`, `dev`.`Chunk`.`content` FROM `dev`.`Chunk` WHERE `dev`.`Chunk`.`hash` IN (?,?) LIMIT ? OFFSET ? | |
| [ | |
| { | |
| filepath: '/foo.ts', | |
| hash: '7d83b585ecd943c562c3c31c1ff290e0d0e0aeb755d0fe4abd471780a8b43c16', | |
| snippetId: 'snippetd-id-test:0.6511770768842615', | |
| chunk: { | |
| hash: '7d83b585ecd943c562c3c31c1ff290e0d0e0aeb755d0fe4abd471780a8b43c16', | |
| content: 'export const foo = 1\n' | |
| } | |
| }, | |
| { | |
| filepath: '/index.tsx', | |
| hash: 'd4445df8a71010339f52e647bb43a3886bf61324895d050ced00c0956cc47798', | |
| snippetId: 'snippetd-id-test:0.6511770768842615', | |
| chunk: { | |
| hash: 'd4445df8a71010339f52e647bb43a3886bf61324895d050ced00c0956cc47798', | |
| content: 'import {foo} from "./foo"\nconsole.log(foo)\n' | |
| } | |
| } | |
| ] |
This file contains hidden or 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
| import { PrismaClient } from "@prisma/client"; | |
| import { minifyCode, expandCode, calcHash } from "../src/lib/minifier"; | |
| const prisma = new PrismaClient({ | |
| log: ["query", "error", "info", "warn"], | |
| }); | |
| (async () => { | |
| let testUser = await prisma.user.upsert({ | |
| where: { | |
| name: "testuser", | |
| }, | |
| create: { | |
| name: "testuser", | |
| }, | |
| update: { | |
| name: "testuser", | |
| }, | |
| }); | |
| const files: { [k: string]: string } = { | |
| "/foo.ts": expandCode("export const foo = 1;"), | |
| "/index.tsx": expandCode(`import { foo } from "./foo";console.log(foo);`), | |
| }; | |
| const snippetId = "snippetd-id-test:" + Math.random().toString(); | |
| await prisma.snippet.create({ | |
| data: { | |
| id: snippetId, | |
| title: "test-snippet", | |
| author: { | |
| connect: { | |
| id: testUser.id, | |
| }, | |
| }, | |
| chunkOwnerships: { | |
| connectOrCreate: Object.entries(files).map(([filepath, content]) => { | |
| const minified = minifyCode(content, filepath); | |
| const hash = calcHash(filepath); | |
| return { | |
| where: { | |
| snippetId_filepath: { | |
| snippetId, | |
| filepath, | |
| }, | |
| }, | |
| create: { | |
| filepath, | |
| chunk: { | |
| connectOrCreate: { | |
| where: { | |
| hash, | |
| }, | |
| create: { | |
| hash, | |
| content: minified, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }; | |
| }), | |
| }, | |
| }, | |
| }); | |
| const data = await prisma.snippet.findFirst({ | |
| where: { | |
| id: snippetId, | |
| }, | |
| include: { | |
| chunkOwnerships: { | |
| include: { | |
| chunk: true, | |
| }, | |
| }, | |
| }, | |
| }); | |
| console.log(data?.chunkOwnerships); | |
| process.exit(0); | |
| })(); |
This file contains hidden or 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
| generator client { | |
| provider = "prisma-client-js" | |
| } | |
| datasource db { | |
| provider = "sqlite" | |
| url = "file:./dev.db" | |
| } | |
| model User { | |
| id String @id @default(uuid()) | |
| name String @unique @default(uuid()) | |
| snippets Snippet[] | |
| } | |
| model Chunk { | |
| hash String @id | |
| content String | |
| referencedBy ChunkOwnership[] | |
| } | |
| model ChunkOwnership { | |
| filepath String | |
| hash String | |
| snippetId String | |
| chunk Chunk @relation(fields: [hash], references: [hash]) | |
| snippet Snippet @relation(fields: [snippetId], references: [id]) | |
| @@id([snippetId, filepath]) | |
| } | |
| model Snippet { | |
| title String | |
| id String @id @default(uuid()) | |
| authorId String? | |
| author User? @relation(fields: [authorId], references: [id]) | |
| chunkOwnerships ChunkOwnership[] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment