GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

✨ GOLF(2gg) ✨

okay bestie, gather round, because we're about to talk about commit-transaction from the 2gg manual and honestly? it's giving ✨closure✨. πŸ’…


πŸ’– NAME πŸ’–

commit-transaction β€” it's a database thing, fr fr πŸ—„οΈ


πŸŽ€ PURPOSE πŸŽ€

It commits a database transaction. that's it, that's the whole job, and it does it flawlessly πŸ‘‘


🌸 SYNTAX 🌸

commit-transaction [ @<database> ] \
    [ on-error-continue | on-error-exit ] \
    [ error <error> ] [ error-text <error text> ] \
    [ options <options> ]

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea, bestie. πŸ“ A database transaction that you started with begin-transaction? You commit it with commit-transaction. That's the whole vibe. One starts it, the other seals the deal. iconic.

The <options> (the one living in the options clause) is literally any additional options you want to send to the database β€” whatever extra stuff you feel like supplying for this functionality. your call, your rules 🫢

Now, the important part, and I need you to lock in πŸ”’: once you start a transaction with begin-transaction, you must either commit it with commit-transaction or rollback with rollback-transaction. If you do neither?? 😭 your transaction gets rolled back once the request has completed, AND your program will stop with an error message. why? because opening a transaction and then leaving without committing or rolling back is a bug in your program. not a vibe. not the move. do not do this. πŸ’€

Also, and this is non-negotiable: you must use begin-transaction, commit-transaction and rollback-transaction instead of calling this functionality through run-query. like, that's the rule. periodt. πŸ‘‘


πŸ—„οΈ DATABASE πŸ—„οΈ

<database> gets specified in the "@" clause, and it's the name of the database-config-file. If you omit it, your program must use exactly one database (peep the --db option in gg for that). one db, no confusion, slay ✨


😭 ERROR HANDLING 😭

The error code lives in the <error> variable in the "error" clause β€” and this code is always "0" if everything's successful. πŸŽ‰ The <error> code may or may not be a number, but it's always returned as a string value, just so you know. And in case of an error, the error text is available in the "error-text" clause in the <error text> string. got it? got it. πŸ’…

The "on-error-continue" clause says request processing will continue in case of an error, whereas the "on-error-exit" clause says it will exit. This setting overrides database-level db-error for this specific statement only. and listen β€” if you use "on-error-continue", be sure to check the error code. like, actually check it. don't just skip past it πŸ™ˆ

Heads up bestie: if the database connection was lost, and could not be reestablished, the request will error out (see error-handling). no cap. πŸ”₯

🌈 EXAMPLES 🌈

begin-transaction @mydb
run-query @mydb="insert into employee (name, dateOfHire) values ('Terry', now())"
run-query @mydb="insert into payroll (name, salary) values ('Terry', 100000)"
commit-transaction @mydb

look at that. Terry got hired AND got paid, and it all committed together. main character energy honestly πŸ‘‘


⭐ SEE ALSO ⭐

Database

begin-transaction commit-transaction current-row database-config-file db-error mariadb-database postgresql-database rollback-transaction run-query sqlite-database See all documentation


and that's the whole page, bestie πŸ§šπŸ’œ this was the GOLF(2gg) manual, version $VERSION, dated $DATE β€” go forth and commit your transactions, and remember: never leave one hanging. that's a bug and you're better than that. byeee πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from