Back

Version 16

11/21/2024
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
import { z } from "https://esm.sh/zod";

// Constants
const SCHEMA_VERSION = 9;
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
const INVENTORY_TABLE = `${KEY}_inventory_${SCHEMA_VERSION}`;
const ACCOUNTS_TABLE = `${KEY}_accounts_${SCHEMA_VERSION}`;

// Existing utility and authentication functions remain the same...

// Inventory Database Initialization
async function initializeInventoryDatabase() {
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS ${INVENTORY_TABLE} (
id TEXT PRIMARY KEY,
address TEXT NOT NULL,
item_name TEXT NOT NULL,
item_type TEXT NOT NULL,
image_url TEXT NOT NULL,
description TEXT,
quantity INTEGER NOT NULL DEFAULT 1,
weight REAL,
rarity TEXT,
durability REAL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(address, item_name, item_type)
)
`);
await sqlite.execute(`
CREATE INDEX IF NOT EXISTS idx_inventory_address
ON ${INVENTORY_TABLE} (address)
`);
}

jamiedubs-glifinventory.web.val.run
Updated: December 2, 2024