Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Brian :cupofcoffee: :rss:
@brianb@fosstodon.org  ·  activity timestamp 7 days ago

#Python folks:

I'm working on a #flask app and I'm wonder when it's preferable to write a database connector object to run queries through vs having queries right in the routes themselves.

Is that helpful? Or is it overhead?

#askfedi

  • Copy link
  • Flag this post
  • Block
stfn
@stfn@fedi.stfn.pl replied  ·  activity timestamp 7 days ago

@brianb I'm all for keeping the routes/views as small as possible and moving all of the business logic and I/O away from them.

And recently I've going one step further, with separate classes for the logic, and other strictly from the I/O. The I/O classes are then used as pluggable dependencies for the logic ones.

  • Copy link
  • Flag this comment
  • Block
Glyph
@glyph@mastodon.social replied  ·  activity timestamp 7 days ago

@brianb for me this is not framework-dependent: a database connector object provides a pivot point for things like instrumentation & logging of database queries, database portability, sharding, etc. Almost always better to have one than not, *unless* you're still in a prototype phase where you're not really sure what the connector's responsibilities should be yet.

  • Copy link
  • Flag this comment
  • Block
Brian :cupofcoffee: :rss:
@brianb@fosstodon.org replied  ·  activity timestamp 7 days ago

@glyph I'm still prototyping, so mostly getting/setting persistent information right now. I just got tired or writing the same query over and over, so I figured this was probably the way to go. Thanks!

  • Copy link
  • Flag this comment
  • Block
Glyph
@glyph@mastodon.social replied  ·  activity timestamp 7 days ago

@brianb once you're repeating yourself it's definitely time for this sort of abstraction!: )

  • Copy link
  • Flag this comment
  • Block
Aaron Brick — אהרן בריק
@aarbrk@mstdn.mx replied  ·  activity timestamp 7 days ago

@brianb No flask experience, but I vote for the abstraction.

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login