API Database Integration
Relational Databases
Relational databases have been the backbone of data storage for many years. They store data in a structured format, using tables with rows and columns. Each row represents a unique record, and each column represents a field of that record. This structure allows for efficient storage and retrieval of data and supports complex operations, like joining data from multiple tables.
Relational databases use Structured Query Language (SQL) to interact with the data. SQL is a powerful language that can perform a variety of operations, including creating, reading, updating, and deleting records (known as CRUD operations).
Because CRUD operations are so common, many web frameworks provide an Object Relational Mapping (ORM) layer that abstracts the database interactions. This allows developers to interact with the database using objects and methods, rather than writing SQL queries directly.
This course will not go into the details of relational databases. We'll leave that for your database courses. Instead, we'll focus on how to use relational databases in your applications.
Serverless Relational Databases
Serverless databases are a relatively new concept. They are fully managed databases that scale automatically and charge based on usage. This means you don't have to worry about provisioning servers, configuring backups, or scaling your database. You simply create a database and start using it. Some common serverless relational databases include:
- Neon (opens in a new tab)
- PlanetScale (opens in a new tab)
- Supabase (opens in a new tab)
- Vercel Postgres (opens in a new tab)
- Microsoft Azure SQL (opens in a new tab)
- Google Cloud SQL (opens in a new tab)
Neon
Neon provides a fully managed serverless PostgreSQL database service. It features a generous free tier and separates storage and compute to offer autoscaling, branching, and unlimited storage. Neon is designed to be scalable, cost-efficient, and easy to use.
Key features of Neon include:
- Serverless Postgres: Neon offers a serverless architecture for PostgreSQL, handling the management and scaling of the database infrastructure.
- Branching: Similar to how code is managed in version control systems, Neon allows instant branching of the Postgres database, useful for test environments and CI/CD pipelines.
- Autoscaling: Compute resources scale dynamically based on demand. The system activates on an incoming connection and scales to zero when not in use, ensuring that you only pay for what you use.
- On-demand Storage: Neon's storage is designed to be fault-tolerant and integrates with cloud object stores like S3 for cold data, aiming for cost optimization and high availability.
- Neon CLI: A command-line interface is provided to manage Neon databases directly from the terminal, allowing users to create projects, manage branches, and retrieve connection strings easily.
- Integration: It seamlessly integrates with other services and platforms like Hasura, Replit, Cloudflare, Vercel, Koyeb, and WunderGraph.
- Open Source: The storage technology used by Neon is open source and written in Rust, employing techniques like copy-on-write for database operations.
Getting Started with Neon
Use this guide to get started with Neon Postgres.
https://neon.tech/docs/guides/nextjs (opens in a new tab)
Using SQL with Neon Postgres
Since we're working in a serverless environment, it is recommended to use the serverless driver. More information can be found here: https://neon.tech/docs/serverless/serverless-driver (opens in a new tab)