FluxaORM: A Golang ORM for MySQL and Redis
Guide
Plugins
GitHub
Guide
Plugins
GitHub
    • Introduction
    • Registry
    • Data pools
    • Entities
    • Entity fields
    • MySQL Indexes
    • Engine
    • ORM
    • Entity Schema
    • Schema Update
    • CRUD
    • Async flush
    • Searching for Entities
    • Redis Search Engine
    • MySQL Queries
    • Local Cache
    • Context Cache
    • Fake Delete
    • Dirty Streams
    • Redis Operations
    • Distributed Lock
    • Virtual Entities
    • Event Broker
    • Queries Log
    • Plugins
    • Log tables

Fake Delete

In a real live scenario, if you delete entity you want to keep in Database marked as deleted instead of actually deleting it. Entity marked as deleted is not returned by GetByID and GetByIDs functions but is not returned by these functions:

  • Search
  • RedisSearch
  • SearchIDs
  • SearchOne
  • GetByIndex
  • GetByUniqueIndex
  • GetByReference
  • GetAll

Enabling Fake Delete

You can enable context cache by adding FakeDelete bool field to your entity:

type UserEntity {
 Name string
 FakeDelete bool
}

Every time you are deleting UserEntity it will be marked as deleted in Database by setting FakeDelete field to ID of entity. FakeDele field generates column in MySQL table the same as ID column and this columns is added automatically added to all MySQL indexes, including unique indexes. This approach allows yoo to avoid duplicate key errors

Example:

userEntity := GetByID[UserEntity](orm, 3)
fluxaorm.Delete(orm, &userEntity)
orm.Flush() // UPDATE UserEntity SET FakeDelete = 3 WHERE ID = 3

userEntity, found := GetByID[UserEntity](orm, 3) // found = true
userEntity.FakeDelete // true

users := Search[UserEntity](orm, NewWhere("1"), nil)
users.Len() // 0

Forcing Entity to be deleted.

You can use ForceDeleteEntity() function to force entity to be deleted from MySQL table.

fluxaorm.ForceDeleteEntity(orm, &userEntity) // DELETE FROM UserEntity WHERE ID = 3

Searching for entities marked as deleted

You can instruct fluxaorm to return in search results also entities marked as deleted with WithFakeDeletes() method on fluxaorm.Where:

where  := fluxaorm.NewWhere("1")
where.WithFakeDeletes()
users = fluxaorm.Search[UserEntity](orm, where, nil) // returns all entities, including marked as deleted
Edit this page
Last Updated: 11/4/25, 3:36 PM
Prev
Context Cache
Next
Dirty Streams