Demo Users Table
demo users table and few users in it
Here’s a simple demo users table with a few sample records that you can use for testing in SQL (e.g.,
PostgreSQL, MySQL, SQLite):
📄 SQL Table Definition
sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(50) DEFAULT 'user',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
🧪 Insert Sample Users
sql
INSERT INTO users (name, email, password, role) VALUES
('Alice Johnson', 'alice@[Link]', 'hashedpassword1', 'admin'),
('Bob Smith', 'bob@[Link]', 'hashedpassword2', 'user'),
('Charlie Lee', 'charlie@[Link]', 'hashedpassword3', 'editor'),
('Dana Kim', 'dana@[Link]', 'hashedpassword4', 'user'),
('Evan Ross', 'evan@[Link]', 'hashedpassword5', 'user');
🔍 Resulting Table Preview
id name email password role created_at
1 Alice Johnson alice@[Link] hashedpassword1 admin (auto timestamp)
2 Bob Smith bob@[Link] hashedpassword2 user (auto timestamp)
3 Charlie Lee charlie@[Link] hashedpassword3 editor (auto timestamp)
4 Dana Kim dana@[Link] hashedpassword4 user (auto timestamp)
5 Evan Ross evan@[Link] hashedpassword5 user (auto timestamp)
Let me know if you want a TypeScript or ORM version (like Sequelize, Prisma, Drizzle, etc.) too.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/4
import { pgTable, serial, text } from 'drizzle-orm/pg-core';
import { db } from '../../config/connection';
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
});
try {
const allUsers = await [Link]().from(users);
[Link](allUsers,"as");
} catch (error) {
[Link](error, "Error fetching users");
fix the schema here
You're almost there! The schema just needs a few improvements:
✅ Fixed Schema with Common Fields:
1. Add notNull() where needed.
2. Add unique() to email if you plan to include it.
3. Add defaultNow() for timestamps if you want a created_at column.
4. Properly define the schema and export it if necessary.
✅ Corrected Version:
ts
import { pgTable, serial, text, varchar, timestamp } from 'drizzle-orm/pg-core';
import { db } from '../../config/connection';
// Define the users table
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: varchar('email', { length: 150 }).notNull().unique(),
password: varchar('password', { length: 255 }).notNull(),
role: varchar('role', { length: 50 }).default('user'),
createdAt: timestamp('created_at').defaultNow(),
});
// Fetch users
try {
const allUsers = await [Link]().from(users);
[Link](allUsers, 'Fetched users');
} catch (error) {
[Link]('Error fetching users:', error);
}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/4
Let me know if you're using this with Hono, [Link], Bun, or anything else—I can tailor it accordingly
(e.g., add Zod schemas, seed data, etc.).
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
// const sql = neon([Link].DATABASE_URL);
const sql = neon("postgres://postgres:12345678@host/test");
export const db = drizzle(sql);
how the db url is gonna look like?
The Neon PostgreSQL connection URL follows this structure:
txt
postgres://<user>:<password>@<host>/<database>?sslmode=require
🧾 Example Breakdown:
Given:
Username: postgres
Password: 12345678
Host: [Link]
Database: test
✅ Your Neon-compatible URL should be:
ts
postgres://postgres:12345678@[Link]/test?
sslmode=require
🔐 Secure Version (Best Practice):
In .env:
env
DATABASE_URL=postgres://postgres:12345678@[Link]/test?
sslmode=require
Then in code:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/4
ts
const sql = neon([Link].DATABASE_URL!);
💡 Note:
sslmode=require is mandatory for Neon (because Neon enforces SSL).
Always use .env to avoid leaking credentials in source code.
If you're testing locally with Drizzle + Neon, ensure your environment supports fetch (like Vite, Bun,
or [Link] Edge Functions).
Let me know if you want a .env, .[Link], or Hono-compatible config too.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/4