I’ve seen two approaches which I’m going to post in the comments to see which one is considered best. Feel free to suggest others.

You are viewing a single thread.
View all comments
3 points

Depends on the use case; the question is, do you need to construct and destroy the connection inside each method, or can you do it once, at the start of the program, and exit at the end?

db = Db(DB_FILE)

post_id = insert_post(db,"hello")
comment_id = insert_comment(db,post_id)

db.close()
permalink
report
reply

Python

!python@programming.dev

Create post

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events
Past

November 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
  • Pythörhead: a Python library for interacting with Lemmy
  • Plemmy: a Python package for accessing the Lemmy API
  • pylemmy pylemmy enables simple access to Lemmy’s API with Python
  • mastodon.py, a Python wrapper for the Mastodon API
Feeds

Community stats

  • 461

    Monthly active users

  • 455

    Posts

  • 2.2K

    Comments