@smartforge/db
v1.0.1
Published
Database schema and client for SmartForge using Drizzle ORM.
Readme
@smartforge/db
Database schema and client for SmartForge using Drizzle ORM.
Installation
npm install @smartforge/db
# or
pnpm add @smartforge/dbUsage
Setup Database Client
import { createDbClient } from "@smartforge/db";
const db = createDbClient(process.env.DATABASE_URL!);Database Schema
The package exports the following tables:
users- User accountsprojects- SmartForge projectsprojectMembers- Project membership and rolescontracts- Smart contractstransactions- Transaction recordsgasUsage- Gas usage trackingcontractEvents- Contract event logs
Example Queries
import { db, users, projects } from "@smartforge/db";
import { eq } from "drizzle-orm";
// Get user by wallet address
const user = await db
.select()
.from(users)
.where(eq(users.walletAddress, "0x..."))
.limit(1);
// Create a project
const [project] = await db
.insert(projects)
.values({
name: "My Project",
ownerId: user.id,
apiKey: "sf_...",
})
.returning();
// Get user's projects
const userProjects = await db
.select()
.from(projects)
.where(eq(projects.ownerId, user.id));Database Migrations
Generate Migrations
cd packages/db
pnpm generateRun Migrations
pnpm migrateSchema Overview
Users
id- UUID primary keywalletAddress- Ethereum address (unique)email- Optional emailrole- User role (admin, writer, reader)createdAt,updatedAt- Timestamps
Projects
id- UUID primary keyname- Project nameownerId- User ID (foreign key)apiKey- Unique API keycreatedAt,updatedAt- Timestamps
Contracts
id- UUID primary keyprojectId- Project ID (foreign key)name- Contract nameaddress- Deployed contract addresschainId- Chain ID (default: 8453 for Base)abi- Contract ABI (JSON)bytecode- Contract bytecodesourceCode- Solidity source codedeploymentStatus- Status (pending, deployed, failed)createdAt,updatedAt- Timestamps
Transactions
id- UUID primary keyprojectId- Project IDcontractId- Contract ID (optional)txHash- Transaction hash (unique)from,to- AddresseschainId- Chain IDfunctionName- Called functionargs- Function arguments (JSON)gasUsed,gasPrice- Gas informationstatus- Transaction statusisGasless- Whether transaction was sponsorederror- Error message (if failed)createdAt- Timestamp
License
ISC
