feat: init project
This commit is contained in:
147
config/config.example.yaml
Normal file
147
config/config.example.yaml
Normal file
@@ -0,0 +1,147 @@
|
||||
# Database Render Application Configuration
|
||||
# Copy this file to config.yaml and modify as needed
|
||||
|
||||
app:
|
||||
name: "Database Render"
|
||||
port: 8080
|
||||
debug: false
|
||||
|
||||
database:
|
||||
# Database type: sqlite, mysql, postgres
|
||||
type: "sqlite"
|
||||
|
||||
# SQLite configuration (used when type is sqlite)
|
||||
path: "data/app.db"
|
||||
|
||||
# MySQL configuration (used when type is mysql)
|
||||
# host: "localhost"
|
||||
# port: 3306
|
||||
# user: "root"
|
||||
# password: "password"
|
||||
# db_name: "database_render"
|
||||
|
||||
# PostgreSQL configuration (used when type is postgres)
|
||||
# host: "localhost"
|
||||
# port: 5432
|
||||
# user: "postgres"
|
||||
# password: "password"
|
||||
# db_name: "database_render"
|
||||
# dsn: "host=localhost port=5432 user=postgres password=password dbname=database_render sslmode=disable"
|
||||
|
||||
# Table configurations
|
||||
tables:
|
||||
- name: "posts"
|
||||
alias: "文章管理"
|
||||
description: "博客文章管理"
|
||||
default: true
|
||||
layout: "cards" # cards or list
|
||||
columns:
|
||||
- name: "id"
|
||||
alias: "ID"
|
||||
type: "int"
|
||||
primary: true
|
||||
hidden: true
|
||||
- name: "title"
|
||||
alias: "标题"
|
||||
type: "string"
|
||||
searchable: true
|
||||
- name: "content"
|
||||
alias: "内容"
|
||||
type: "text"
|
||||
render_type: "markdown"
|
||||
searchable: true
|
||||
- name: "category"
|
||||
alias: "分类"
|
||||
type: "string"
|
||||
searchable: true
|
||||
render_type: "tag"
|
||||
values:
|
||||
technology:
|
||||
label: "技术"
|
||||
color: "#3b82f6"
|
||||
life:
|
||||
label: "生活"
|
||||
color: "#10b981"
|
||||
work:
|
||||
label: "工作"
|
||||
color: "#f59e0b"
|
||||
- name: "tags"
|
||||
alias: "标签"
|
||||
type: "string"
|
||||
searchable: true
|
||||
- name: "created_at"
|
||||
alias: "创建时间"
|
||||
type: "datetime"
|
||||
render_type: "time"
|
||||
- name: "updated_at"
|
||||
alias: "更新时间"
|
||||
type: "datetime"
|
||||
render_type: "time"
|
||||
|
||||
- name: "users"
|
||||
alias: "用户管理"
|
||||
description: "系统用户管理"
|
||||
layout: "list"
|
||||
columns:
|
||||
- name: "id"
|
||||
alias: "ID"
|
||||
type: "int"
|
||||
primary: true
|
||||
hidden: true
|
||||
- name: "username"
|
||||
alias: "用户名"
|
||||
type: "string"
|
||||
searchable: true
|
||||
- name: "email"
|
||||
alias: "邮箱"
|
||||
type: "string"
|
||||
searchable: true
|
||||
- name: "full_name"
|
||||
alias: "姓名"
|
||||
type: "string"
|
||||
searchable: true
|
||||
- name: "status"
|
||||
alias: "状态"
|
||||
type: "string"
|
||||
render_type: "tag"
|
||||
values:
|
||||
active:
|
||||
label: "激活"
|
||||
color: "#10b981"
|
||||
inactive:
|
||||
label: "未激活"
|
||||
color: "#ef4444"
|
||||
pending:
|
||||
label: "待审核"
|
||||
color: "#f59e0b"
|
||||
- name: "created_at"
|
||||
alias: "创建时间"
|
||||
type: "datetime"
|
||||
render_type: "time"
|
||||
|
||||
# Logging configuration
|
||||
logging:
|
||||
level: "info" # debug, info, warn, error
|
||||
format: "json" # json, text
|
||||
output: "stdout" # stdout, stderr, file
|
||||
file: "logs/app.log" # Only used when output is file
|
||||
|
||||
# Server configuration
|
||||
server:
|
||||
read_timeout: 30s
|
||||
write_timeout: 30s
|
||||
idle_timeout: 60s
|
||||
|
||||
# Security configuration
|
||||
security:
|
||||
cors:
|
||||
enabled: true
|
||||
allow_origins: ["*"]
|
||||
allow_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
||||
allow_headers: ["Origin", "Content-Type", "Accept", "Authorization"]
|
||||
|
||||
# Cache configuration
|
||||
cache:
|
||||
enabled: false
|
||||
ttl: 5m
|
||||
max_size: 100
|
||||
230
config/config.yaml
Normal file
230
config/config.yaml
Normal file
@@ -0,0 +1,230 @@
|
||||
# Database Render Application Configuration
|
||||
|
||||
app:
|
||||
name: "Database Render"
|
||||
port: 9080
|
||||
debug: false
|
||||
|
||||
database:
|
||||
type: "sqlite"
|
||||
path: "data/app.db"
|
||||
|
||||
# Table configurations
|
||||
tables:
|
||||
posts:
|
||||
alias: "文章管理"
|
||||
description: "博客文章管理"
|
||||
page_size: 10
|
||||
fields:
|
||||
id:
|
||||
type: "int"
|
||||
alias: "ID"
|
||||
hidden: true
|
||||
title:
|
||||
type: "string"
|
||||
alias: "标题"
|
||||
searchable: true
|
||||
size: "large"
|
||||
content:
|
||||
type: "text"
|
||||
alias: "内容"
|
||||
hidden: true # Hide from list view, show in detail
|
||||
markdown: true
|
||||
category:
|
||||
type: "string"
|
||||
alias: "分类"
|
||||
searchable: true
|
||||
colors:
|
||||
Technology: "#3b82f6"
|
||||
Programming: "#8b5cf6"
|
||||
"Web Development": "#10b981"
|
||||
DevOps: "#f59e0b"
|
||||
"Data Science": "#ef4444"
|
||||
Lifestyle: "#ec4899"
|
||||
tags:
|
||||
type: "string"
|
||||
alias: "标签"
|
||||
searchable: true
|
||||
status:
|
||||
type: "string"
|
||||
alias: "状态"
|
||||
searchable: true
|
||||
colors:
|
||||
published: "#10b981"
|
||||
draft: "#6b7280"
|
||||
pending: "#f59e0b"
|
||||
view_count:
|
||||
type: "int"
|
||||
alias: "浏览量"
|
||||
created_at:
|
||||
type: "time"
|
||||
alias: "创建时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
updated_at:
|
||||
type: "time"
|
||||
alias: "更新时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
|
||||
users:
|
||||
alias: "用户管理"
|
||||
description: "系统用户管理"
|
||||
page_size: 10
|
||||
fields:
|
||||
id:
|
||||
type: "int"
|
||||
alias: "ID"
|
||||
hidden: true
|
||||
username:
|
||||
type: "string"
|
||||
alias: "用户名"
|
||||
searchable: true
|
||||
email:
|
||||
type: "string"
|
||||
alias: "邮箱"
|
||||
searchable: true
|
||||
full_name:
|
||||
type: "string"
|
||||
alias: "姓名"
|
||||
searchable: true
|
||||
bio:
|
||||
type: "text"
|
||||
alias: "简介"
|
||||
max_length: 200
|
||||
status:
|
||||
type: "string"
|
||||
alias: "状态"
|
||||
searchable: true
|
||||
colors:
|
||||
active: "#10b981"
|
||||
inactive: "#ef4444"
|
||||
pending: "#f59e0b"
|
||||
role:
|
||||
type: "string"
|
||||
alias: "角色"
|
||||
searchable: true
|
||||
colors:
|
||||
admin: "#ef4444"
|
||||
user: "#3b82f6"
|
||||
last_login:
|
||||
type: "time"
|
||||
alias: "最后登录"
|
||||
format: "2006-01-02 15:04:05"
|
||||
created_at:
|
||||
type: "time"
|
||||
alias: "创建时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
updated_at:
|
||||
type: "time"
|
||||
alias: "更新时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
|
||||
categories:
|
||||
alias: "分类管理"
|
||||
description: "文章分类管理"
|
||||
page_size: 10
|
||||
fields:
|
||||
id:
|
||||
type: "int"
|
||||
alias: "ID"
|
||||
hidden: true
|
||||
name:
|
||||
type: "string"
|
||||
alias: "名称"
|
||||
searchable: true
|
||||
slug:
|
||||
type: "string"
|
||||
alias: "别名"
|
||||
searchable: true
|
||||
description:
|
||||
type: "text"
|
||||
alias: "描述"
|
||||
max_length: 200
|
||||
color:
|
||||
type: "string"
|
||||
alias: "颜色"
|
||||
render_type: "color"
|
||||
sort_order:
|
||||
type: "int"
|
||||
alias: "排序"
|
||||
is_active:
|
||||
type: "bool"
|
||||
alias: "激活"
|
||||
render_type: "bool"
|
||||
created_at:
|
||||
type: "time"
|
||||
alias: "创建时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
updated_at:
|
||||
type: "time"
|
||||
alias: "更新时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
|
||||
comments:
|
||||
alias: "评论管理"
|
||||
description: "文章评论管理"
|
||||
page_size: 15
|
||||
fields:
|
||||
id:
|
||||
type: "int"
|
||||
alias: "ID"
|
||||
hidden: true
|
||||
post_id:
|
||||
type: "int"
|
||||
alias: "文章ID"
|
||||
user_id:
|
||||
type: "int"
|
||||
alias: "用户ID"
|
||||
author_name:
|
||||
type: "string"
|
||||
alias: "作者"
|
||||
searchable: true
|
||||
author_email:
|
||||
type: "string"
|
||||
alias: "邮箱"
|
||||
searchable: true
|
||||
content:
|
||||
type: "text"
|
||||
alias: "内容"
|
||||
max_length: 500
|
||||
status:
|
||||
type: "string"
|
||||
alias: "状态"
|
||||
searchable: true
|
||||
colors:
|
||||
approved: "#10b981"
|
||||
pending: "#f59e0b"
|
||||
rejected: "#ef4444"
|
||||
created_at:
|
||||
type: "time"
|
||||
alias: "创建时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
updated_at:
|
||||
type: "time"
|
||||
alias: "更新时间"
|
||||
format: "2006-01-02 15:04:05"
|
||||
|
||||
# Logging configuration
|
||||
logging:
|
||||
level: "info"
|
||||
format: "json"
|
||||
output: "stdout"
|
||||
|
||||
# Server configuration
|
||||
server:
|
||||
read_timeout: 30s
|
||||
write_timeout: 30s
|
||||
idle_timeout: 60s
|
||||
|
||||
# Security configuration
|
||||
security:
|
||||
cors:
|
||||
enabled: true
|
||||
allow_origins: ["*"]
|
||||
allow_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
||||
allow_headers: ["Origin", "Content-Type", "Accept"]
|
||||
|
||||
# Cache configuration
|
||||
cache:
|
||||
enabled: false
|
||||
ttl: 5m
|
||||
max_size: 100
|
||||
346
config/schema.example.sql
Normal file
346
config/schema.example.sql
Normal file
@@ -0,0 +1,346 @@
|
||||
-- Database Render Application - Sample Database Schema
|
||||
-- This file contains sample database tables for testing the application
|
||||
|
||||
-- Posts table (blog posts/articles)
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
content TEXT,
|
||||
category VARCHAR(50),
|
||||
tags VARCHAR(255),
|
||||
author_id INTEGER,
|
||||
status VARCHAR(20) DEFAULT 'draft',
|
||||
view_count INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Users table
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
full_name VARCHAR(100),
|
||||
password_hash VARCHAR(255),
|
||||
avatar_url VARCHAR(255),
|
||||
bio TEXT,
|
||||
status VARCHAR(20) DEFAULT 'active',
|
||||
role VARCHAR(20) DEFAULT 'user',
|
||||
last_login DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Categories table
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(100) UNIQUE NOT NULL,
|
||||
slug VARCHAR(100) UNIQUE NOT NULL,
|
||||
description TEXT,
|
||||
color VARCHAR(7),
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Tags table
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(50) UNIQUE NOT NULL,
|
||||
slug VARCHAR(50) UNIQUE NOT NULL,
|
||||
color VARCHAR(7),
|
||||
description TEXT,
|
||||
usage_count INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Post-Tag relationship table
|
||||
CREATE TABLE IF NOT EXISTS post_tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
tag_id INTEGER NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE,
|
||||
UNIQUE(post_id, tag_id)
|
||||
);
|
||||
|
||||
-- Comments table
|
||||
CREATE TABLE IF NOT EXISTS comments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
user_id INTEGER,
|
||||
author_name VARCHAR(100),
|
||||
author_email VARCHAR(255),
|
||||
content TEXT NOT NULL,
|
||||
parent_id INTEGER,
|
||||
status VARCHAR(20) DEFAULT 'pending',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (parent_id) REFERENCES comments(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Media/Attachments table
|
||||
CREATE TABLE IF NOT EXISTS media (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
original_filename VARCHAR(255),
|
||||
file_path VARCHAR(500),
|
||||
file_size INTEGER,
|
||||
mime_type VARCHAR(100),
|
||||
alt_text VARCHAR(255),
|
||||
title VARCHAR(255),
|
||||
description TEXT,
|
||||
uploaded_by INTEGER,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (uploaded_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Sample data insertion
|
||||
-- Insert sample users
|
||||
INSERT OR IGNORE INTO users (username, email, full_name, bio, role) VALUES
|
||||
('admin', 'admin@example.com', 'System Administrator', 'System administrator account', 'admin'),
|
||||
('john_doe', 'john@example.com', 'John Doe', 'Technology enthusiast and blogger', 'user'),
|
||||
('jane_smith', 'jane@example.com', 'Jane Smith', 'Content creator and writer', 'user'),
|
||||
('bob_wilson', 'bob@example.com', 'Bob Wilson', 'Software developer and tech reviewer', 'user');
|
||||
|
||||
-- Insert sample categories
|
||||
INSERT OR IGNORE INTO categories (name, slug, description, color) VALUES
|
||||
('Technology', 'technology', 'Latest technology trends and developments', '#3b82f6'),
|
||||
('Programming', 'programming', 'Programming tutorials and best practices', '#8b5cf6'),
|
||||
('Web Development', 'web-development', 'Web development articles and tutorials', '#10b981'),
|
||||
('DevOps', 'devops', 'DevOps practices and tools', '#f59e0b'),
|
||||
('Data Science', 'data-science', 'Data science and machine learning', '#ef4444'),
|
||||
('Lifestyle', 'lifestyle', 'Personal development and lifestyle', '#ec4899');
|
||||
|
||||
-- Insert sample tags
|
||||
INSERT OR IGNORE INTO tags (name, slug, color, description) VALUES
|
||||
('Go', 'go', '#00add8', 'Go programming language'),
|
||||
('Python', 'python', '#3776ab', 'Python programming language'),
|
||||
('JavaScript', 'javascript', '#f7df1e', 'JavaScript programming language'),
|
||||
('Docker', 'docker', '#2496ed', 'Docker containerization'),
|
||||
('Kubernetes', 'kubernetes', '#326ce5', 'Kubernetes orchestration'),
|
||||
('React', 'react', '#61dafb', 'React framework'),
|
||||
('Vue.js', 'vuejs', '#4fc08d', 'Vue.js framework'),
|
||||
('Database', 'database', '#4479a1', 'Database technologies'),
|
||||
('API', 'api', '#68d391', 'API development'),
|
||||
('Security', 'security', '#f56565', 'Security practices');
|
||||
|
||||
-- Insert sample posts
|
||||
INSERT OR IGNORE INTO posts (title, content, category, tags, author_id, status) VALUES
|
||||
('Getting Started with Go and Fiber Framework', '# Getting Started with Go and Fiber
|
||||
|
||||
This is a comprehensive guide to building web applications with Go and the Fiber framework.
|
||||
|
||||
## Introduction
|
||||
|
||||
Fiber is an Express.js inspired web framework written in Go. It provides a robust set of features for building web applications and APIs.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
go get github.com/gofiber/fiber/v2
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, World!")
|
||||
})
|
||||
|
||||
app.Listen(":3000")
|
||||
}
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
Fiber provides an excellent foundation for building high-performance web applications in Go.', 'Programming', 'Go,Web Development,API', 2, 'published'),
|
||||
|
||||
('Modern Database Design Best Practices', '# Modern Database Design Best Practices
|
||||
|
||||
Learn the essential principles of designing scalable and maintainable databases.
|
||||
|
||||
## Key Principles
|
||||
|
||||
1. **Normalization**: Reduce data redundancy
|
||||
2. **Indexing**: Improve query performance
|
||||
3. **Data Types**: Choose appropriate data types
|
||||
4. **Constraints**: Ensure data integrity
|
||||
|
||||
## Example Schema
|
||||
|
||||
Here''s an example of a well-designed user table:
|
||||
|
||||
```sql
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
```
|
||||
|
||||
## Performance Tips
|
||||
|
||||
- Use appropriate indexes
|
||||
- Consider partitioning for large tables
|
||||
- Regular database maintenance', 'Technology', 'Database,Design,Best Practices', 3, 'published'),
|
||||
|
||||
('Container Orchestration with Kubernetes', '# Container Orchestration with Kubernetes
|
||||
|
||||
Master the art of container orchestration with Kubernetes.
|
||||
|
||||
## What is Kubernetes?
|
||||
|
||||
Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers.
|
||||
|
||||
## Key Features
|
||||
|
||||
- **Service Discovery**: Automatic container discovery
|
||||
- **Load Balancing**: Distribute traffic across containers
|
||||
- **Storage Orchestration**: Mount storage systems
|
||||
- **Self-Healing**: Automatic container restarts
|
||||
- **Secret Management**: Secure sensitive data
|
||||
|
||||
## Getting Started
|
||||
|
||||
```bash
|
||||
# Start a local cluster
|
||||
minikube start
|
||||
|
||||
# Deploy an application
|
||||
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
|
||||
|
||||
# Expose the deployment
|
||||
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use namespaces for organization
|
||||
- Implement health checks
|
||||
- Monitor resource usage
|
||||
- Use ConfigMaps for configuration', 'DevOps', 'Kubernetes,Docker,Containerization', 4, 'published'),
|
||||
|
||||
('Building RESTful APIs with Best Practices', '# Building RESTful APIs with Best Practices
|
||||
|
||||
Create robust and scalable RESTful APIs following industry standards.
|
||||
|
||||
## REST Principles
|
||||
|
||||
- **Stateless**: Each request contains all necessary information
|
||||
- **Resource-Based**: URLs represent resources
|
||||
- **HTTP Methods**: Use appropriate HTTP verbs (GET, POST, PUT, DELETE)
|
||||
- **Status Codes**: Return appropriate HTTP status codes
|
||||
|
||||
## API Design Guidelines
|
||||
|
||||
### 1. Version Your API
|
||||
```
|
||||
/api/v1/users
|
||||
/api/v2/users
|
||||
```
|
||||
|
||||
### 2. Use Plural Nouns
|
||||
```
|
||||
GET /users
|
||||
POST /users
|
||||
GET /users/123
|
||||
```
|
||||
|
||||
### 3. Filtering and Pagination
|
||||
```
|
||||
GET /users?page=1&limit=10&sort=name&order=asc
|
||||
```
|
||||
|
||||
### 4. Error Handling
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
"code": "VALIDATION_ERROR",
|
||||
"message": "Email is required",
|
||||
"details": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- Use HTTPS
|
||||
- Implement rate limiting
|
||||
- Validate input data
|
||||
- Use authentication and authorization', 'Programming', 'API,REST,Security', 2, 'published'),
|
||||
|
||||
('React State Management in 2024', '# React State Management in 2024
|
||||
|
||||
Explore modern state management solutions for React applications.
|
||||
|
||||
## State Management Options
|
||||
|
||||
### 1. React Context API
|
||||
Built-in solution for sharing state across components.
|
||||
|
||||
### 2. Redux Toolkit
|
||||
Predictable state container with great developer tools.
|
||||
|
||||
### 3. Zustand
|
||||
Lightweight and simple state management.
|
||||
|
||||
### 4. Jotai
|
||||
Atomic approach to state management.
|
||||
|
||||
## Choosing the Right Solution
|
||||
|
||||
| Solution | Best For | Bundle Size |
|
||||
|----------|----------|-------------|
|
||||
| Context | Simple apps | Small |
|
||||
| Redux | Complex apps | Large |
|
||||
| Zustand | Medium apps | Small |
|
||||
| Jotai | Atomic state | Small |
|
||||
|
||||
## Code Example
|
||||
|
||||
```javascript
|
||||
// Using Zustand
|
||||
import { create } from ''zustand''
|
||||
|
||||
const useStore = create((set) => ({
|
||||
count: 0,
|
||||
increment: () => set((state) => ({ count: state.count + 1 })),
|
||||
}))
|
||||
```
|
||||
|
||||
## Performance Tips
|
||||
|
||||
- Use React.memo for expensive components
|
||||
- Implement proper memoization
|
||||
- Consider code splitting for large state', 'Web Development', 'React,JavaScript,State Management', 3, 'published');
|
||||
|
||||
-- Insert sample comments
|
||||
INSERT OR IGNORE INTO comments (post_id, user_id, content, status) VALUES
|
||||
(1, 3, 'Great tutorial! Very helpful for getting started with Fiber.', 'approved'),
|
||||
(1, 4, 'Thanks for sharing this. The examples are really clear.', 'approved'),
|
||||
(2, 2, 'Excellent overview of database design principles!', 'approved'),
|
||||
(3, 1, 'Kubernetes can be overwhelming, but this guide makes it approachable.', 'approved'),
|
||||
(4, 3, 'RESTful API best practices are so important. Great article!', 'approved');
|
||||
|
||||
-- Insert post-tag relationships
|
||||
INSERT OR IGNORE INTO post_tags (post_id, tag_id) VALUES
|
||||
(1, 1), (1, 9), (1, 10),
|
||||
(2, 8), (2, 9),
|
||||
(3, 4), (3, 5),
|
||||
(4, 9), (4, 10),
|
||||
(5, 6), (5, 7), (5, 10);
|
||||
346
config/schema.sql
Normal file
346
config/schema.sql
Normal file
@@ -0,0 +1,346 @@
|
||||
-- Database Render Application - Sample Database Schema
|
||||
-- This file contains sample database tables for testing the application
|
||||
|
||||
-- Posts table (blog posts/articles)
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
content TEXT,
|
||||
category VARCHAR(50),
|
||||
tags VARCHAR(255),
|
||||
author_id INTEGER,
|
||||
status VARCHAR(20) DEFAULT 'draft',
|
||||
view_count INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Users table
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
full_name VARCHAR(100),
|
||||
password_hash VARCHAR(255),
|
||||
avatar_url VARCHAR(255),
|
||||
bio TEXT,
|
||||
status VARCHAR(20) DEFAULT 'active',
|
||||
role VARCHAR(20) DEFAULT 'user',
|
||||
last_login DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Categories table
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(100) UNIQUE NOT NULL,
|
||||
slug VARCHAR(100) UNIQUE NOT NULL,
|
||||
description TEXT,
|
||||
color VARCHAR(7),
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Tags table
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(50) UNIQUE NOT NULL,
|
||||
slug VARCHAR(50) UNIQUE NOT NULL,
|
||||
color VARCHAR(7),
|
||||
description TEXT,
|
||||
usage_count INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Post-Tag relationship table
|
||||
CREATE TABLE IF NOT EXISTS post_tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
tag_id INTEGER NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE,
|
||||
UNIQUE(post_id, tag_id)
|
||||
);
|
||||
|
||||
-- Comments table
|
||||
CREATE TABLE IF NOT EXISTS comments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
user_id INTEGER,
|
||||
author_name VARCHAR(100),
|
||||
author_email VARCHAR(255),
|
||||
content TEXT NOT NULL,
|
||||
parent_id INTEGER,
|
||||
status VARCHAR(20) DEFAULT 'pending',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (parent_id) REFERENCES comments(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Media/Attachments table
|
||||
CREATE TABLE IF NOT EXISTS media (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
original_filename VARCHAR(255),
|
||||
file_path VARCHAR(500),
|
||||
file_size INTEGER,
|
||||
mime_type VARCHAR(100),
|
||||
alt_text VARCHAR(255),
|
||||
title VARCHAR(255),
|
||||
description TEXT,
|
||||
uploaded_by INTEGER,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (uploaded_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Sample data insertion
|
||||
-- Insert sample users
|
||||
INSERT OR IGNORE INTO users (username, email, full_name, bio, role) VALUES
|
||||
('admin', 'admin@example.com', 'System Administrator', 'System administrator account', 'admin'),
|
||||
('john_doe', 'john@example.com', 'John Doe', 'Technology enthusiast and blogger', 'user'),
|
||||
('jane_smith', 'jane@example.com', 'Jane Smith', 'Content creator and writer', 'user'),
|
||||
('bob_wilson', 'bob@example.com', 'Bob Wilson', 'Software developer and tech reviewer', 'user');
|
||||
|
||||
-- Insert sample categories
|
||||
INSERT OR IGNORE INTO categories (name, slug, description, color) VALUES
|
||||
('Technology', 'technology', 'Latest technology trends and developments', '#3b82f6'),
|
||||
('Programming', 'programming', 'Programming tutorials and best practices', '#8b5cf6'),
|
||||
('Web Development', 'web-development', 'Web development articles and tutorials', '#10b981'),
|
||||
('DevOps', 'devops', 'DevOps practices and tools', '#f59e0b'),
|
||||
('Data Science', 'data-science', 'Data science and machine learning', '#ef4444'),
|
||||
('Lifestyle', 'lifestyle', 'Personal development and lifestyle', '#ec4899');
|
||||
|
||||
-- Insert sample tags
|
||||
INSERT OR IGNORE INTO tags (name, slug, color, description) VALUES
|
||||
('Go', 'go', '#00add8', 'Go programming language'),
|
||||
('Python', 'python', '#3776ab', 'Python programming language'),
|
||||
('JavaScript', 'javascript', '#f7df1e', 'JavaScript programming language'),
|
||||
('Docker', 'docker', '#2496ed', 'Docker containerization'),
|
||||
('Kubernetes', 'kubernetes', '#326ce5', 'Kubernetes orchestration'),
|
||||
('React', 'react', '#61dafb', 'React framework'),
|
||||
('Vue.js', 'vuejs', '#4fc08d', 'Vue.js framework'),
|
||||
('Database', 'database', '#4479a1', 'Database technologies'),
|
||||
('API', 'api', '#68d391', 'API development'),
|
||||
('Security', 'security', '#f56565', 'Security practices');
|
||||
|
||||
-- Insert sample posts
|
||||
INSERT OR IGNORE INTO posts (title, content, category, tags, author_id, status) VALUES
|
||||
('Getting Started with Go and Fiber Framework', '# Getting Started with Go and Fiber
|
||||
|
||||
This is a comprehensive guide to building web applications with Go and the Fiber framework.
|
||||
|
||||
## Introduction
|
||||
|
||||
Fiber is an Express.js inspired web framework written in Go. It provides a robust set of features for building web applications and APIs.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
go get github.com/gofiber/fiber/v2
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, World!")
|
||||
})
|
||||
|
||||
app.Listen(":3000")
|
||||
}
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
Fiber provides an excellent foundation for building high-performance web applications in Go.', 'Programming', 'Go,Web Development,API', 2, 'published'),
|
||||
|
||||
('Modern Database Design Best Practices', '# Modern Database Design Best Practices
|
||||
|
||||
Learn the essential principles of designing scalable and maintainable databases.
|
||||
|
||||
## Key Principles
|
||||
|
||||
1. **Normalization**: Reduce data redundancy
|
||||
2. **Indexing**: Improve query performance
|
||||
3. **Data Types**: Choose appropriate data types
|
||||
4. **Constraints**: Ensure data integrity
|
||||
|
||||
## Example Schema
|
||||
|
||||
Here''s an example of a well-designed user table:
|
||||
|
||||
```sql
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
```
|
||||
|
||||
## Performance Tips
|
||||
|
||||
- Use appropriate indexes
|
||||
- Consider partitioning for large tables
|
||||
- Regular database maintenance', 'Technology', 'Database,Design,Best Practices', 3, 'published'),
|
||||
|
||||
('Container Orchestration with Kubernetes', '# Container Orchestration with Kubernetes
|
||||
|
||||
Master the art of container orchestration with Kubernetes.
|
||||
|
||||
## What is Kubernetes?
|
||||
|
||||
Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers.
|
||||
|
||||
## Key Features
|
||||
|
||||
- **Service Discovery**: Automatic container discovery
|
||||
- **Load Balancing**: Distribute traffic across containers
|
||||
- **Storage Orchestration**: Mount storage systems
|
||||
- **Self-Healing**: Automatic container restarts
|
||||
- **Secret Management**: Secure sensitive data
|
||||
|
||||
## Getting Started
|
||||
|
||||
```bash
|
||||
# Start a local cluster
|
||||
minikube start
|
||||
|
||||
# Deploy an application
|
||||
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
|
||||
|
||||
# Expose the deployment
|
||||
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use namespaces for organization
|
||||
- Implement health checks
|
||||
- Monitor resource usage
|
||||
- Use ConfigMaps for configuration', 'DevOps', 'Kubernetes,Docker,Containerization', 4, 'published'),
|
||||
|
||||
('Building RESTful APIs with Best Practices', '# Building RESTful APIs with Best Practices
|
||||
|
||||
Create robust and scalable RESTful APIs following industry standards.
|
||||
|
||||
## REST Principles
|
||||
|
||||
- **Stateless**: Each request contains all necessary information
|
||||
- **Resource-Based**: URLs represent resources
|
||||
- **HTTP Methods**: Use appropriate HTTP verbs (GET, POST, PUT, DELETE)
|
||||
- **Status Codes**: Return appropriate HTTP status codes
|
||||
|
||||
## API Design Guidelines
|
||||
|
||||
### 1. Version Your API
|
||||
```
|
||||
/api/v1/users
|
||||
/api/v2/users
|
||||
```
|
||||
|
||||
### 2. Use Plural Nouns
|
||||
```
|
||||
GET /users
|
||||
POST /users
|
||||
GET /users/123
|
||||
```
|
||||
|
||||
### 3. Filtering and Pagination
|
||||
```
|
||||
GET /users?page=1&limit=10&sort=name&order=asc
|
||||
```
|
||||
|
||||
### 4. Error Handling
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
"code": "VALIDATION_ERROR",
|
||||
"message": "Email is required",
|
||||
"details": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- Use HTTPS
|
||||
- Implement rate limiting
|
||||
- Validate input data
|
||||
- Use authentication and authorization', 'Programming', 'API,REST,Security', 2, 'published'),
|
||||
|
||||
('React State Management in 2024', '# React State Management in 2024
|
||||
|
||||
Explore modern state management solutions for React applications.
|
||||
|
||||
## State Management Options
|
||||
|
||||
### 1. React Context API
|
||||
Built-in solution for sharing state across components.
|
||||
|
||||
### 2. Redux Toolkit
|
||||
Predictable state container with great developer tools.
|
||||
|
||||
### 3. Zustand
|
||||
Lightweight and simple state management.
|
||||
|
||||
### 4. Jotai
|
||||
Atomic approach to state management.
|
||||
|
||||
## Choosing the Right Solution
|
||||
|
||||
| Solution | Best For | Bundle Size |
|
||||
|----------|----------|-------------|
|
||||
| Context | Simple apps | Small |
|
||||
| Redux | Complex apps | Large |
|
||||
| Zustand | Medium apps | Small |
|
||||
| Jotai | Atomic state | Small |
|
||||
|
||||
## Code Example
|
||||
|
||||
```javascript
|
||||
// Using Zustand
|
||||
import { create } from ''zustand''
|
||||
|
||||
const useStore = create((set) => ({
|
||||
count: 0,
|
||||
increment: () => set((state) => ({ count: state.count + 1 })),
|
||||
}))
|
||||
```
|
||||
|
||||
## Performance Tips
|
||||
|
||||
- Use React.memo for expensive components
|
||||
- Implement proper memoization
|
||||
- Consider code splitting for large state', 'Web Development', 'React,JavaScript,State Management', 3, 'published');
|
||||
|
||||
-- Insert sample comments
|
||||
INSERT OR IGNORE INTO comments (post_id, user_id, content, status) VALUES
|
||||
(1, 3, 'Great tutorial! Very helpful for getting started with Fiber.', 'approved'),
|
||||
(1, 4, 'Thanks for sharing this. The examples are really clear.', 'approved'),
|
||||
(2, 2, 'Excellent overview of database design principles!', 'approved'),
|
||||
(3, 1, 'Kubernetes can be overwhelming, but this guide makes it approachable.', 'approved'),
|
||||
(4, 3, 'RESTful API best practices are so important. Great article!', 'approved');
|
||||
|
||||
-- Insert post-tag relationships
|
||||
INSERT OR IGNORE INTO post_tags (post_id, tag_id) VALUES
|
||||
(1, 1), (1, 9), (1, 10),
|
||||
(2, 8), (2, 9),
|
||||
(3, 4), (3, 5),
|
||||
(4, 9), (4, 10),
|
||||
(5, 6), (5, 7), (5, 10);
|
||||
Reference in New Issue
Block a user