added unique fields

This commit is contained in:
2026-03-04 10:10:57 +06:00
parent f3f2b7b394
commit 0481cde1c3
8 changed files with 309 additions and 9 deletions

View File

@@ -0,0 +1,2 @@
{"age":31,"created":"2026-03-04T09:07:22+06:00","email":"john@example.com","id":1,"name":"John Doe"}
{"age":35,"created":"2026-03-04T09:07:22+06:00","email":"bob@example.com","id":3,"name":"Bob Johnson"}

View File

@@ -21,7 +21,7 @@ func main() {
initOptions := &linedb.LineDbInitOptions{
CacheSize: 1000,
CacheTTL: 5 * time.Minute,
DBFolder: "./data",
DBFolder: "./examples/basic/data",
Collections: []linedb.JSONLFileOptions{
{
CollectionName: "users",
@@ -41,21 +41,31 @@ func main() {
}
defer db.Close()
//delete all entries from users collection
if _, err := db.Delete(map[string]any{}, "users", linedb.LineDbAdapterOptions{}); err != nil {
log.Fatalf("Failed to delete users: %v", err)
}
fmt.Println("All entries deleted from users collection")
// Создаем тестовых пользователей
users := []any{
map[string]any{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"created": time.Now().Format(time.RFC3339),
},
map[string]any{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"age": 25,
"created": time.Now().Format(time.RFC3339),
},
map[string]any{
"id": 3,
"name": "Bob Johnson",
"email": "bob@example.com",
"age": 35,
@@ -94,17 +104,24 @@ func main() {
}
// Обновляем пользователя
updateData := map[string]any{"age": 31}
updateData := map[string]any{"age": 31, "email": "jane@example.com"}
updateFilter := map[string]any{"email": "john@example.com"}
updatedUsers, err := db.Update(updateData, "users", updateFilter, linedb.LineDbAdapterOptions{})
if err != nil {
log.Fatalf("Failed to update user: %v", err)
log.Printf("Failed to update user: %v", err)
}
updateData = map[string]any{"age": 31, "email": "john@example.com"}
updateFilter = map[string]any{"email": "john@example.com"}
updatedUsers, err = db.Update(updateData, "users", updateFilter, linedb.LineDbAdapterOptions{})
if err != nil {
log.Printf("Failed again to update user: %v", err)
}
fmt.Printf("Updated %d users\n", len(updatedUsers))
// Удаляем пользователя
deleteFilter := map[string]any{"email": "bob@example.com"}
deleteFilter := map[string]any{"email": "jane@example.com"}
deletedUsers, err := db.Delete(deleteFilter, "users", linedb.LineDbAdapterOptions{})
if err != nil {
log.Fatalf("Failed to delete user: %v", err)