Telegram Group & Telegram Channel
📢 GORM теперь поддерживает дженерики — работа с БД в Go стала ещё проще и безопаснее!

С версии GORM v1.30.0 появилась полноценная поддержка дженериков (Go 1.18+), которая позволяет писать более выразительный и типобезопасный код без шаблонных повторов.

🔧 Пример:


ctx := context.Background()

// Создание
gorm.G[User](db).Create(ctx, &User{Name: "Alice"})

// Поиск
user, err := gorm.G[User](db).Where("name = ?", "Alice").First(ctx)

// Обновление
gorm.G[User](db).Where("id = ?", user.ID).Update(ctx, "age", 30)

// Удаление
gorm.G[User](db).Where("id = ?", user.ID).Delete(ctx)


Что это даёт:
• Типобезопасность на этапе компиляции
• Более компактный и читаемый код
• Лёгкая интеграция с OnConflict, Joins, Hints, Preload и пр.
• Улучшенный DX (developer experience)

📎 Документация: https://gorm.io/docs/the_generics_way.html

Если ты пишешь на Go и используешь GORM — самое время перейти на новый стиль.



tg-me.com/golang_books/986
Create:
Last Update:

📢 GORM теперь поддерживает дженерики — работа с БД в Go стала ещё проще и безопаснее!

С версии GORM v1.30.0 появилась полноценная поддержка дженериков (Go 1.18+), которая позволяет писать более выразительный и типобезопасный код без шаблонных повторов.

🔧 Пример:


ctx := context.Background()

// Создание
gorm.G[User](db).Create(ctx, &User{Name: "Alice"})

// Поиск
user, err := gorm.G[User](db).Where("name = ?", "Alice").First(ctx)

// Обновление
gorm.G[User](db).Where("id = ?", user.ID).Update(ctx, "age", 30)

// Удаление
gorm.G[User](db).Where("id = ?", user.ID).Delete(ctx)


Что это даёт:
• Типобезопасность на этапе компиляции
• Более компактный и читаемый код
• Лёгкая интеграция с OnConflict, Joins, Hints, Preload и пр.
• Улучшенный DX (developer experience)

📎 Документация: https://gorm.io/docs/the_generics_way.html

Если ты пишешь на Go и используешь GORM — самое время перейти на новый стиль.

BY Golang Books




Share with your friend now:
tg-me.com/golang_books/986

View MORE
Open in Telegram


Golang Books Telegram | DID YOU KNOW?

Date: |

The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

Golang Books from us


Telegram Golang Books
FROM USA