-
-
Save kuc-arc-f/33c70560fad13341ef13b4689b79435c to your computer and use it in GitHub Desktop.
drizzle-ORM, write time
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
| DB_FILE_NAME=file:local.db |
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
| { | |
| "type": "module", | |
| "scripts": {}, | |
| "dependencies": { | |
| "@libsql/client": "^0.15.10", | |
| "dotenv": "^17.2.1", | |
| "drizzle-orm": "^0.44.4", | |
| "tsx": "^4.20.4" | |
| }, | |
| "devDependencies": { | |
| "drizzle-kit": "^0.31.4" | |
| } | |
| } |
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 { int, sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core"; | |
| import { sql } from 'drizzle-orm'; | |
| export const todos = sqliteTable('todo', { | |
| id: integer('id').primaryKey({ autoIncrement: true }), | |
| title: text('title').notNull(), | |
| created_at: text('created_at').notNull().default(new Date().toISOString()), | |
| updated_at: text('updated_at').notNull().default(new Date().toISOString()) | |
| }); | |
| export type Todo = typeof todos.$inferSelect; | |
| export type NewItem = typeof todos.$inferInsert; | |
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 { drizzle } from 'drizzle-orm/libsql'; | |
| import { eq } from 'drizzle-orm'; | |
| import { todos } from './src/db/schema'; | |
| import 'dotenv/config' | |
| (async () => { | |
| console.time('proc-time'); | |
| const db = drizzle(process.env.DB_FILE_NAME); | |
| let targetNum = 1; | |
| for (let step = 0; step < 1000; step++) { | |
| targetNum = step + 1; | |
| let setValue = `title:${targetNum}`; | |
| let newItem = { | |
| title: setValue, | |
| created_at: new Date().toISOString(), | |
| updated_at: new Date().toISOString(), | |
| }; | |
| const result = await db.insert(todos).values(newItem).returning(); | |
| } | |
| console.timeEnd('proc-time'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment