mirror of
https://github.com/Floriansylvain/GoAntiSqlPOC.git
synced 2026-08-19 11:43:24 +02:00
feat: update methods & improved demo
This commit is contained in:
@@ -4,7 +4,7 @@ This project demonstrates a proof of concept for a database solution in Go that
|
||||
|
||||
## Disclaimer ⚠️
|
||||
|
||||
This is not clean architecture friendly yet.
|
||||
This project is not clean architecture friendly, yet.
|
||||
|
||||
## Core Features
|
||||
|
||||
@@ -15,23 +15,23 @@ This is not clean architecture friendly yet.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- **main.go**: Example usage demonstrating user creation and address management
|
||||
- **store/db.go**: Database connection management
|
||||
- **store/user.go**: User entity operations (create, find, list)
|
||||
- **main.go**: Example usage demonstrating CRUD operations and relationships
|
||||
- **store/db.go**: Database connection management with in-memory storage
|
||||
- **store/user.go**: User entity operations (create, find, update, list)
|
||||
- **store/address.go**: Address entity operations with user relationships
|
||||
|
||||
## How It Works
|
||||
|
||||
### Database Management
|
||||
|
||||
The project uses BadgerDB as the underlying storage engine. The `store.InitDB()` function sets up the database connection with a singleton pattern using `sync.Once` to ensure it's only initialized once.
|
||||
The project uses BadgerDB as the underlying storage engine. The `store.InitDB()` function sets up an in-memory database connection with a singleton pattern using `sync.Once` to ensure it's only initialized once.
|
||||
|
||||
### Data Models
|
||||
|
||||
The project defines strongly typed Go structs to enforce schema:
|
||||
|
||||
- `User`: Stores user information with ID, name, email, and password
|
||||
- `Address`: Stores address information with reference to a user
|
||||
- `Address`: Stores address information with reference to a user via UserID
|
||||
|
||||
### Data Access Pattern
|
||||
|
||||
@@ -46,6 +46,10 @@ addr, _ := store.AddAddressToUser(user.ID, "123 Main St", "Paris", "75001")
|
||||
|
||||
// List addresses for a user
|
||||
addresses, _ := store.ListAddressesByUserID(user.ID)
|
||||
|
||||
// Update user data
|
||||
user.Name = "Bobby"
|
||||
store.UpdateUser(user)
|
||||
```
|
||||
|
||||
### "Relational" Modeling
|
||||
@@ -54,6 +58,7 @@ The project demonstrates relationship modeling between users and addresses:
|
||||
|
||||
1. Each address has a `UserID` field linking it to its owner
|
||||
2. The `ListAddressesByUserID` function retrieves all addresses for a specific user
|
||||
3. Updates to either entity maintain relationship integrity
|
||||
|
||||
### Data Consistency
|
||||
|
||||
@@ -61,8 +66,20 @@ The project implements data consistency features:
|
||||
|
||||
- Email uniqueness enforcement using an email-to-ID index
|
||||
- Transaction support for atomic operations
|
||||
- Error handling for constraint violations
|
||||
|
||||
## Dependencies
|
||||
### Terminal Demo
|
||||
|
||||
- [BadgerDB v4](https://github.com/dgraph-io/badger) - Embedded key-value database
|
||||
- [Google UUID](https://github.com/google/uuid) - For generating unique identifiers
|
||||
The main.go file provides a demonstration that showcases:
|
||||
|
||||
1. User creation with validation
|
||||
2. Address management (create, read, update)
|
||||
3. Relationship handling (users have multiple addresses)
|
||||
4. Constraint enforcement (unique emails)
|
||||
5. Entity retrieval by ID and other fields
|
||||
|
||||
## Running the Demo
|
||||
|
||||
```bash
|
||||
go run main.go
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user