This document discusses Parsec, a domain-specific language (DSL) for parsing expressions. It describes how Parsec uses monads and state to parse input sequentially. It also lists various parsing functions in Parsec like try, choice, many, and skip. Finally, it mentions several Parsec implementations for languages like Haskell, Rust, JavaScript, Python, and links to related projects from Dwarfartisan.
This document discusses Parsec, a domain-specific language (DSL) for parsing expressions. It describes how Parsec uses monads and state to parse input sequentially. It also lists various parsing functions in Parsec like try, choice, many, and skip. Finally, it mentions several Parsec implementations for languages like Haskell, Rust, JavaScript, Python, and links to related projects from Dwarfartisan.
22. fetch all
f o r row i n c u r s o r . f e t c h a l l ( ) :
...
. . . . . .
23. or fetch each
w h i l e True :
row = c u r s o r . f e t c h o n e ( )
i f row :
...
else :
break
...
. . . . . .
24. 事务
conn . s e t i s o l a t i o n l e v e l ( n )
...
conn . commit ( ) #o r . r o l l b a c k ( )
. . . . . .
25. 典型的 DBAPI 应用
import p s y c o p g 2
w i t h conn a s p s y c o p g 2 . c o n n e c t ( . . . ) :
c u r = conn . c u r s o r ( )
try :
c u r . e x e c u t e ( ’ s e l e c t ∗ from t where k e y=? ’ ,
f o r row i n c u r . f e t c h o n e ( ) :
dosomthing . . .
conn . commit ( )
except e :
logger . log ( e )
conn . r o l l b a c ( )
. . . . . .