Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created August 21, 2025 03:22
Show Gist options
  • Select an option

  • Save kuc-arc-f/33c70560fad13341ef13b4689b79435c to your computer and use it in GitHub Desktop.

Select an option

Save kuc-arc-f/33c70560fad13341ef13b4689b79435c to your computer and use it in GitHub Desktop.
drizzle-ORM, write time
DB_FILE_NAME=file:local.db
{
"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"
}
}
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;
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