TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Notanorm: Lightweight Db Layer for Python

1 点作者 earonesty大约 4 年前

1 comment

earonesty大约 4 年前
I find full-blown orm&#x27;s both restrictive and clumsy for smaller projects. But also i like to use a base layer that allows me to connect to different db&#x27;s with a unified syntax.<p>The syntax&#x2F;structure below seems pretty clean (suggestions welcome), and because it doesn&#x27;t do that much, it seems unlikely to stop working randomly.<p><pre><code> db = notanorm.SqliteDb(&quot;:memory:&quot;) db.query(&quot;create table foo(bar)&quot;) db.insert(&quot;foo&quot;, bar=22) db.select(&quot;foo&quot;) db.select(&quot;foo&quot;, bar=[22,33,44]) </code></pre> (that last statement is a placeholder-generated IN clause)<p>It&#x27;s left as an exercise for the reader to structure create statements properly (mysql and sqlite syntax is actually pretty compatible).<p>But realistically, your DBA doesn&#x27;t want you running create statements from python anyway.<p>Many libs I write wind up being discarded eventually or replaced with something better. This one has stuck around for 4 years now, and seems to be pretty useful.<p>It currently only has mysql&#x2F;python drivers but writing a new driver is pretty simple.