A Next.js task management application with Drizzle ORM and Neon PostgreSQL database.
This project uses Drizzle ORM with a Neon PostgreSQL database.
- Create a free account at Neon
- Create a new project
- Copy your database connection string from the dashboard
-
Copy the example environment file:
cp env.example .env.local
-
Update
.env.localwith your Neon database URL:DATABASE_URL="postgresql://username:password@hostname/database?sslmode=require"
Run the following commands to set up your database:
# Generate and push the schema to your database
npm run db:push
# Or if you prefer migrations:
npm run db:generate
npm run db:migratenpm run db:generate- Generate migration filesnpm run db:migrate- Run migrationsnpm run db:push- Push schema changes directly to databasenpm run db:studio- Open Drizzle Studio to view/edit data
First, run the development server:
npm run devOpen http://localhost:3000 with your browser to see the result.
This project uses TanStack Query for efficient data fetching and caching. All database operations are available as React hooks.
useBuckets()- Fetch all bucketsuseBucket(id)- Fetch a single bucket by IDuseCreateBucket()- Create a new bucketuseUpdateBucket()- Update an existing bucketuseDeleteBucket()- Delete a bucket
useTasks()- Fetch all tasksuseTasksByBucket(bucketId)- Fetch tasks for a specific bucketuseTask(id)- Fetch a single task by IDuseCreateTask()- Create a new taskuseUpdateTask()- Update an existing taskuseDeleteTask()- Delete a taskuseToggleTaskCompletion()- Toggle task completion status
import { useBuckets, useCreateBucket } from "@/lib/hooks/use-queries";
function MyComponent() {
// Query hook
const { data: buckets, isLoading } = useBuckets();
// Mutation hook
const createBucket = useCreateBucket();
const handleCreateBucket = async () => {
try {
await createBucket.mutateAsync({
name: "Work",
color: "#3b82f6",
});
} catch (error) {
console.error("Failed to create bucket:", error);
}
};
if (isLoading) return <div>Loading...</div>;
return (
<div>
{buckets?.map((bucket) => (
<div key={bucket.id}>{bucket.name}</div>
))}
<button onClick={handleCreateBucket}>Create Bucket</button>
</div>
);
}- Automatic Caching: Queries are cached and automatically revalidated
- Optimistic Updates: Mutations can update the cache immediately
- Error Handling: Built-in error states and retry logic
- Loading States: Automatic loading indicators
- Background Refetching: Data stays fresh with background updates
- DevTools: React Query DevTools included for debugging
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.