usar drizzle-kit

This commit is contained in:
Cat /dev/Nulo 2023-12-23 20:29:55 -03:00
parent d72150f578
commit e65328d025
8 changed files with 1186 additions and 25 deletions

View file

@ -0,0 +1,10 @@
import type { Config } from "drizzle-kit";
export default {
schema: "./schema.ts",
out: "./drizzle",
driver: "better-sqlite",
dbCredentials: {
url: "../scraper/sqlite.db",
},
} satisfies Config;

View file

@ -0,0 +1,8 @@
CREATE TABLE `precios` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`ean` text NOT NULL,
`fetched_at` integer NOT NULL,
`precio_centavos` integer,
`in_stock` integer,
`url` text NOT NULL
);

View file

@ -0,0 +1,65 @@
{
"version": "5",
"dialect": "sqlite",
"id": "88aa0254-106e-424e-ab66-417ff44bbf0b",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"precios": {
"name": "precios",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"ean": {
"name": "ean",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fetched_at": {
"name": "fetched_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"precio_centavos": {
"name": "precio_centavos",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"in_stock": {
"name": "in_stock",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View file

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1703373860006,
"tag": "0000_blushing_sabretooth",
"breakpoints": true
}
]
}

11
db-datos/migrate.ts Normal file
View file

@ -0,0 +1,11 @@
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "./schema.js";
const sqlite = new Database("../scraper/sqlite.db");
const db = drizzle(sqlite, { schema });
await migrate(db, { migrationsFolder: "./drizzle" });
sqlite.close();

View file

@ -1,5 +1,6 @@
{
"name": "db-datos",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
@ -10,6 +11,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"better-sqlite3": "^9.2.2",
"drizzle-kit": "^0.20.7",
"drizzle-orm": "^0.29.1"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.8"
}
}

View file

@ -7,6 +7,8 @@ export const precios = sqliteTable("precios", {
precioCentavos: integer("precio_centavos"),
inStock: integer("in_stock", { mode: "boolean" }),
url: text("url").notNull(),
// warcRecordId: text("warc_record_id"),
// parserVersion: integer("parser_version"),
});
export type Precio = typeof precios.$inferSelect;

File diff suppressed because it is too large Load diff