TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Supercharge SQLite with Ruby Functions

159 pointsby julik4 months ago

11 comments

ncruces4 months ago
Taking full advantage of SQLite&#x27;s extensibility is a center piece of my Go driver.<p>It started due to having to reimplement the OS layer in Go because of tech constraints, but it means you _can_ implement VFSes, UDFs (scalar, aggregates and windows), and virtual tables in Go, with reasonable performance and nice APIs.<p>I also made a point of dogfooding this as much as possible, with a bunch of extensions and a few custom VFSes that use the same APIs available to clients of the library.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3&#x2F;tree&#x2F;main&#x2F;ext">https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3&#x2F;tree&#x2F;main&#x2F;ext</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3&#x2F;tree&#x2F;main&#x2F;vfs#custom-vfses">https:&#x2F;&#x2F;github.com&#x2F;ncruces&#x2F;go-sqlite3&#x2F;tree&#x2F;main&#x2F;vfs#custom-v...</a>
评论 #42839684 未加载
评论 #42849023 未加载
bob10294 months ago
You can hypothetically write your entire product in SQL with appropriate bindings to SQLite. For me, SQL with CTEs is a very compelling way to model tricky business logic. Building a SQL-based rules engine is trivial if your host language has a good SQLite library.<p>This thing starts to grow legs once you realize you can recursively get into the rabbit hole by binding something like an Execute_Sql UDF - You can store the actual scripts within the same schema they operate on. Treating your code as data means you can do things like transactional updates of business logic while the system is serving live requests. You also get simple reflection &amp; search over the business logic.
maCDzP4 months ago
Is this the same thing as create_function for python?<p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sqlite3.html#sqlite3.Connection.create_function" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sqlite3.html#sqlite3.Conne...</a>
评论 #42840135 未加载
tobyhinloopen4 months ago
Ive nothing to say but “that’s cool”. I want to try this in NodeJS!<p>I suppose using functions defined by the host with SQLite is cheaper than using similarly defined functions in databases that are separated by a network. I wonder what the overhead is.<p>Also, what’s with the weird UUIDs? Why not use UUIDv7 if you want time-ordered UUIDs?
评论 #42840147 未加载
评论 #42841630 未加载
评论 #42838906 未加载
评论 #42840194 未加载
评论 #42838770 未加载
评论 #42838711 未加载
mingodad4 months ago
Also available with LUA <a href="http:&#x2F;&#x2F;lua.sqlite.org&#x2F;index.cgi&#x2F;doc&#x2F;tip&#x2F;doc&#x2F;lsqlite3.wiki#db_create_function" rel="nofollow">http:&#x2F;&#x2F;lua.sqlite.org&#x2F;index.cgi&#x2F;doc&#x2F;tip&#x2F;doc&#x2F;lsqlite3.wiki#db...</a>
评论 #42839351 未加载
评论 #42840371 未加载
steve_gh4 months ago
There are also some good libs for SQLite. This is the standard set that I use. <a href="https:&#x2F;&#x2F;github.com&#x2F;nalgeon&#x2F;sqlean">https:&#x2F;&#x2F;github.com&#x2F;nalgeon&#x2F;sqlean</a>
igravious4 months ago
from the comments:<p><pre><code> [Python](https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sqlite3.html#sqlite3.Connection.create_function)</code></pre> <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sqlite3.html#sqlite3.Connection.create_function" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sqlite3.html#sqlite3.Conne...</a><p><pre><code> [Lua](http:&#x2F;&#x2F;lua.sqlite.org&#x2F;index.cgi&#x2F;doc&#x2F;tip&#x2F;doc&#x2F;lsqlite3.wiki#db_create_function)</code></pre> <a href="http:&#x2F;&#x2F;lua.sqlite.org&#x2F;index.cgi&#x2F;doc&#x2F;tip&#x2F;doc&#x2F;lsqlite3.wiki#db_create_function" rel="nofollow">http:&#x2F;&#x2F;lua.sqlite.org&#x2F;index.cgi&#x2F;doc&#x2F;tip&#x2F;doc&#x2F;lsqlite3.wiki#db...</a><p><pre><code> [Node.js](https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;sqlite.html#databasefunctionname-options-function)</code></pre> <a href="https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;sqlite.html#databasefunctionname-options-function" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;sqlite.html#databasefunctionname-opti...</a><p><pre><code> [PHP](https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;sqlite3.createfunction.php)</code></pre> <a href="https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;sqlite3.createfunction.php" rel="nofollow">https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;sqlite3.createfunction.php</a>
melvinroest4 months ago
I happen to work with BigQuery since recently and heard you can do UDFs with JavaScript. Good to know that this is a thing with more databases. I didn&#x27;t need to use UDFs up until this point but now that I know about it a bit more, I just might as JS happens to be a strong language of mine (currently not using it professionally).
评论 #42840168 未加载
throw_m2393394 months ago
Yes, I remember using that in PHP, very handy before sqlite JSON support, since it also worked with aggregate functions.<p><a href="https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;sqlite3.createfunction.php" rel="nofollow">https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;sqlite3.createfunction.php</a>
评论 #42844932 未加载
dennisvdvliet4 months ago
That is pretty cool. And good to see you still doing talks.
Alifatisk4 months ago
What an interesting find