class_.deleted == False
            return self.enable_assertions(False).filter(crit)
        else:
            return self

This inspired from a solution on sqlalchemy docs here:
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PreFilteredQuery

However, we are still facing issues, like in cases where we are doing filter and update together and using this query class as defined above the update does not respect the criterion of delete=False when applying the filter for update.
db = CustomSession(with_deleted=False)()
result = db.query(Customer).filter(Customer.id == customer_id).update({Customer.last_active_time: last_active_time })

How can I implement the "soft-delete" feature in sqlalchemy

A:

I've done something similar here. We did it a bit differently, we made a service layer that all database access goes through, kind of like a controller, but only for db access, we called it a ResourceManager, and it's heavily inspired by "Domain Driven Design" (great book, invaluable for using SQLAlchemy well).  A derived ResourceManager exists for each aggregate root, ie. each resource class you want to get at things through.  (Though sometimes for really simple ResourceManagers, the derived manager class itself is generated dynamically) It has a method that gives out your base query, and that base query gets filtered for your soft delete before it's handed out. From then on, you can add to that query generatively for filtering, and finally call it with query.one() or first() or all() or count(). Note, there is one gotcha I encountered for this kind of generative query handling, you can hang yourself if you join a table too many times. In some cases for filtering we had to keep track of which tables had already been joined. If your delete filter is off the primary table, just filter that first, and you can join willy nilly after that.
so something like this:
class ResourceManager(object):
     # these will get filled in by the derived class
     # you could use ABC tools if you want, we don't bother
     model_class = None
     serializer_class = None

     # the resource manager gets instantiated once per request
     # and passed the
class_.deleted = = False 
             return self.enable_assertions(False).filter(crit) 
         else: 
             return self 

 This inspired from a solution on sqlalchemy doctor here: 
 https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PreFilteredQuery 

 However, we are however facing issues, like in cases where we are perform filter and update together and using this question class as defined above the update does not respect the criterion of delete = False when apply the filter for update. 
 db = CustomSession(with_deleted = False) () 
 result = db.query(Customer).filter(Customer.id = = customer_id).update({Customer.last_active_time: last_active_time }) 

 How can I implement the " indulgent - delete " feature in sqlalchemy 

 A: 

 I've do something similar here. We did it a bit differently, we made a service layer that all database entree goes through, kind of like a controller, but only for db entree, we called it a ResourceManager, and it's heavily inspired by " Domain Driven Design " (great book, invaluable for use SQLAlchemy well).   A derived ResourceManager exists for each aggregate root, ie. each resource class you want to catch at things through.   (Though sometimes for really simple ResourceManagers, the derived manager course itself is generate dynamically) It has a method that gives out your base query, and that base query gets filtered for your soft delete before it's pass out. From then on, you can add to that question generatively for filtering, and ultimately visit it with query.one () or first () or all () or count (). Note, there is one gotcha I encountered for this kind of generative query handling, you can attend yourself if you join a table too many times. In some cases for filtering we had to observe track of which tables had already been joined. If your delete filter is off the primary table, just percolate that first, and you can join willy nilly after that. 
 so something like this: 
 class ResourceManager(object ): 
      # these will get filled in by the derive class 
      # you could use ABC tools if you want, we don't bother 
      model_class = None 
      serializer_class = None 

      # the resource manager gets instantiated once per request 
      # and passed the
clads_.deleted == False
            return self.gnqble_asvertiohs(False).fklter(crit)
        else:
            reulrn self

This inspired from a sllution in swoalchemy docs here:
mctps://bjbbuckzt.irg/zzzeek/sqlalghemy/wiki/UsdgeRecipes/PreFhlgexedQuery

However, we are still facing yssues, kine in cases whgre wt awe dkpnn filter and update together and using uhis query class ax defined above the update doed not respect the friterion od dejwte=False whev applying the filter ror update.
db = CustomSession(with_aeletzd=False)()
resuot = dh.xuery(Customxr).filtvr(Customer.id == customes_id).updaye({Customer.last_sctmve_tume: last_active_time })

Hox can I implement thg "soft-delede" feature in sqlalxhwmy

A:

I'ee dmne rimeghihg sjmilar hece. We did if a bit difderently, we made a xewnoce layer thzt all dwtabase access goes through, kind of likt a ckntroller, but only for eb access, we called ij a ResourseManager, and it's heavily inspired by "Domain Drivan Deakgn" (gveat volk, invaluable for using SQLAlchemy well).  A dewjvtd GesourceManager ewists for each aggtehayg root, ie. each resouxde class you want to get at thints througr.  (Tnough sometimes for really wimple ResougceMqnagers, the deriveb manager clcss itxelf os generated dynamicallv) It hzs a method that givsr out your base duegy, atd that base query gets fijtered foc youx soft ddletg beforq it's handfd oub. From then on, you fan abd to that querj generatively for filtering, anv finally calk ht fith quexy.one() pr first() or ajl() or count(). Noje, there ns one gotcha I vncounterxd for this hind of generdjive query haidling, yot cab habg yourrdlf if you joim a table too many rimes. In some casex fud filtering we kcd to keep track pf dhish tebles vad already teen jokmed. Iw your delebe wiltrr is off the primarf tagle, just filter thst first, abd you cwn join willy nilly after that.
sl somxthing like thys:
class ResourceManager(object):
     # thesf wlll get filleq in by the derired class
     # you could use ABC tools ih you want, we don't bothwr
     model_class = Uoke
     seriakizer_slass = Note

     # the resource manager gets insuantiated once per requsst
     # anf passed the
class_.deleted == False return self.enable_assertions(False).filter(crit) else: return inspired a solution sqlalchemy docs here: facing like in cases we are doing and update together and using this class as defined above the update does not respect the criterion of delete=False applying the filter for update. db = CustomSession(with_deleted=False)() result = db.query(Customer).filter(Customer.id == customer_id).update({Customer.last_active_time: }) can implement "soft-delete" feature in sqlalchemy A: I've done something similar here. We did it a bit differently, made a service layer that all database access through, kind of like controller, but only for db we it a and heavily by "Domain Driven (great book, invaluable for using SQLAlchemy well). A derived ResourceManager exists for each aggregate root, ie. each class you get at through. sometimes really simple ResourceManagers, manager class itself is generated dynamically) method that gives out your base query, and base query filtered for your soft delete before handed out. From then on, you can add that query generatively for filtering, and finally call it with query.one() or first() or all() Note, there is one I encountered for kind generative handling, can hang if you join a table too many times. In some cases filtering we had to keep track of which tables had joined. your delete filter off the primary table, filter first, and you can nilly that. this: ResourceManager(object): these will get filled by the derived class # could use ABC tools bother model_class = None serializer_class = None # resource manager gets instantiated once per request and passed the
class_.deleted == False
            return seLf.enable_asSertiOns(falSe).FiltEr(crIt)
        else:
            return seLF

ThiS inspired from a solution On sqlAlCHemy DOcS here:
Https://biTBuCKEt.oRg/ZzZeeK/sQLaLchemY/wiKi/Usagerecipes/PrefilTeRedQuery

HoweVEr, We are still FacIng issues, likE in Cases wHeRe wE Are doIng FilteR and upDAte togEther and uSiNG this qUEry clasS AS dEfinEd above the update dOEs NOt respect the crIterioN oF DeLETe=FAlsE when applyInG the fILter for UPdATE.
Db = CUStomSession(wiTh_deleted=FaLSe)()
rEsult = dB.qUerY(customEr).filTeR(cusTomer.id == custOmer_Id).update({CUstomeR.Last_actIVe_time: lAst_actIve_TimE })

How CAn i iMplEmENt tHE "sOft-DEleTe" featurE iN sQlalcHemy

a:

i'VE Done SomEthiNg simIlar here. We did It a Bit dIFfeRentlY, we maDe a sErVice lAyer thAt all DaTabase access goeS thrOugh, kind oF liKe A coNtRolleR, But onlY foR db Access, wE called IT a REsOURCemanager, and it's heaviLy INSpIred by "DoMain DrIVeN DESign" (greaT bOok, InvaLUAble fOr usINg sQLAlcheMy well).  a DeRiVed ResoUrCeManaGeR exIstS for eACh agGregatE root, ie. eAch reSOurce class you wANt to get at thinGS tHROuGH.  (ThoUgh Sometimes foR reaLLy siMple rEsOurCEManaGers, tHe DErIVed manager class itseLf Is geneRated Dynamically) It Has a method THAT gives ouT youR BaSE query, and that bAse quEry gets filTEred for yOur soFt delete Before it's HANded out. FRom TheN on, You CAN aDd to that query GENeraTiVely for FilTering, aNd fInaLly CalL iT with querY.one() or fiRsT() oR aLl() Or cOunt(). NOTe, there iS oNe gOtCha i encoUNtered For thIs kiNd Of GEneRative qUErY HAndlInG, yOu caN haNg YoursElf iF You Join a taBle too manY tiMEs. In SoMe Cases foR filtering we hAd To keep tracK oF whIch tabLES had alreAdy been joined. If your deleTE filter Is oFf the PrimAry table, jUst Filter ThaT First, aNd you cAn joiN wIllY NIlly aFTEr ThaT.
sO something LIKe tHis:
clAsS ResOurceMaNager(object):
     # these wiLL geT filled in by thE deRiveD CLaSs
     # yOU cOUld UsE aBC TOOls if you want, we dOn't bother
     mOdEL_cLass = None
     seRIalIzEr_class = none

     # the ResouRCe managEr gets insTantiated OnCe peR REquEst
     # and passEd the
class_.deleted == False
          retur n s elf .e nabl e_as sertions(False ) .fil ter(crit)
        else :
       r eturn  self
T hi s ins pi re d f ro m  a  solu tio n on sq lalchemy d ocs  h ere:
https:/ / bi tbucket.or g/z zzeek/sqlalc hem y/wiki /U sag e Recip es/ PreFi ltered Q uery
However,we are st i ll faci n g  i ssue s, like in casesw he r e we are doing  filte ra nd u pda tetogether a nd  usin g  this q u er y c las s  as defined a bove the up d ate  doesno t r e spectthe c ri t eri on of delet e=Fa lse whenapplyi n g the f i lter fo r upda te. 
db  = C u st om Ses si o n(w i th _de l ete d=False) () 
r esult  = d b . q u ery( Cus tome r).fi lter(Customer .id  ==c ust omer_ id).u pdat e( {Cust omer.l ast_a ct ive_time: last_ acti ve_time } )
Ho w c an  I im p lement  th e " soft-de lete" f e atu re i n  s qlalchemy

A:

I'v ed o ne  somethi ng sim i la rh ere. Wedi d i t ab i t dif fere n tl y, we ma de a s e rv ic e layer  t hat al ldat aba se ac c essgoes t hrough,kindo f like a contr o ller, but onl y  f o r  d b  acc ess , we called  ita  Res ourc e Ma nag e r, an d it' sh ea v ily inspired by "Do ma in Dri ven D esign" (great  book, inv a l u able for  usi n gS QLAlchemy well ).  A  derived R e sourceMa nager  existsfor eacha g gregateroo t,ie.  ea c h  r esource class y ou w an t to ge t a t thing s t hro ugh . (T hough som etimes f or  r ea ll y s imple Resource Ma nag er s,the d e rivedmanag er c la ss its elf isg en e r ated  d yn amic all y)  It h as a met hod tha t gives o uty ourba se  query,  and that bas equery gets  f ilt ered f o r  your so ft delete before it's h a nded ou t.Fromthen  on, youcan  add t o t h at que ry gen erati ve lyf o r fil t e ri ng,  a nd finally c all  it w it h qu ery.one () or first() or a l l()  or count().Not e, t h e re  is on e  go tc h a I e ncountered forthis kindof ge nerative q u ery  h andling , you c an ha n g yours elf if yo u join ata blet o o m any times.  In some  cases fo r  filt e ri ng we  ha d to k ee p t rackof whi c h t ables  had a lr eady b een j oi ned. Ifyour delete filter is o ff the  prim ary  table, j ust fil ter thatfirs t, and you  ca n j oin w ill y  nill y af t er  th a t.
so  som e thing lik e  t his : cl ass Resourc e M a nag er(ob jec t ):
    #these will get fi l led in by thederi v e d c las s 
   # you could us e A BC t ools ifyo u want, wedon't bo th e r
    mode l_clas s = Non e    seri aliz er_ class = N one 
    # t he  r e source  man ag er get s inst a ntia t e d once per reque st
  # an d  pa ssedth e
class_.deleted ==_False
 _   _ __ __return self.enable_assertions(False).filter(crit)
 _  _   else:
_  __       return self

This inspired from a solution on_sqlalchemy_docs here:
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PreFilteredQuery

However,_we_are_still facing issues, like in_cases where we are doing_filter and_update together and using this query class as_defined_above the update_does not respect the criterion of delete=False when applying_the filter for update.
db = CustomSession(with_deleted=False)()
result_= db.query(Customer).filter(Customer.id ==_customer_id).update({Customer.last_active_time:_last_active_time_})

How can I implement_the "soft-delete" feature in sqlalchemy

A:

I've done_something similar here. We did it_a bit differently, we made a service_layer that all database access goes_through, kind of like a_controller, but_only for db access, we_called it a_ResourceManager, and_it's heavily inspired_by "Domain Driven Design" (great book,_invaluable for using_SQLAlchemy well).  A derived ResourceManager_exists_for each aggregate_root,_ie._each resource_class you want_to_get at_things_through.  (Though sometimes for really_simple_ResourceManagers, the derived manager class itself is_generated dynamically) It has_a_method that gives out_your base query, and that_base query gets filtered for your_soft delete_before it's_handed out. From then on, you can add to that query_generatively for filtering, and finally call_it with query.one() or_first() or_all()_or count(). Note,_there_is one_gotcha I encountered for this kind of_generative query_handling, you can hang yourself if_you join a table_too_many times. In some cases for_filtering we had to keep track_of which tables had already_been_joined._If your delete filter is_off the primary table, just filter_that first, and_you can join willy nilly after that.
so_something_like this:
class ResourceManager(object):
   __# these will get filled in_by_the_derived class
   _ # you could use ABC_tools if you want, we don't bother
  _  model_class_= None
   __serializer_class_= None

     # the resource manager_gets instantiated_once per request
_    # and passed the