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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Bringing psql’s \d to your web browser

76 点作者 gmac大约 1 年前

8 条评论

arp242大约 1 年前
I always thought that most \-commands in psql were just frontends for queries? For example:<p><pre><code> % psql db_name (1)=# \set ECHO_HIDDEN (1)=# \d ********* QUERY ********** SELECT n.nspname as &quot;Schema&quot;, c.relname as &quot;Name&quot;, CASE c.relkind WHEN &#x27;r&#x27; THEN &#x27;table&#x27; WHEN &#x27;v&#x27; THEN &#x27;view&#x27; WHEN &#x27;m&#x27; THEN &#x27;materialized view&#x27; WHEN &#x27;i&#x27; THEN &#x27;index&#x27; WHEN &#x27;S&#x27; TH EN &#x27;sequence&#x27; WHEN &#x27;t&#x27; THEN &#x27;TOAST table&#x27; WHEN &#x27;f&#x27; THEN &#x27;foreign table&#x27; WHEN &#x27;p&#x27; THEN &#x27;partitioned table&#x27; WHEN &#x27;I&#x27; THEN &#x27;partit ioned index&#x27; END as &quot;Type&quot;, pg_catalog.pg_get_userbyid(c.relowner) as &quot;Owner&quot; FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam WHERE c.relkind IN (&#x27;r&#x27;,&#x27;p&#x27;,&#x27;v&#x27;,&#x27;m&#x27;,&#x27;S&#x27;,&#x27;f&#x27;,&#x27;&#x27;) AND n.nspname &lt;&gt; &#x27;pg_catalog&#x27; AND n.nspname !~ &#x27;^pg_toast&#x27; AND n.nspname &lt;&gt; &#x27;information_schema&#x27; AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; ************************** List of relations Schema │ Name │ Type │ Owner ────────┼────────────────────────────────────────┼──────────┼──────── ... </code></pre> I re-implemented quite a bit of that in a PostgreSQL management tool I built, based just on the ECHO_HIDDEN queries. Never even had to look at any C code.<p>I&#x27;m not sure if I entirely follow what translating C to JS gives you, other than a bit of (fairly simple) parsing of \cmd and flags? I didn&#x27;t look too carefully at the code, so maybe I&#x27;m missing something.
评论 #40302023 未加载
评论 #40301378 未加载
评论 #40301138 未加载
评论 #40302089 未加载
williamjackson大约 1 年前
The fact that this is not a manual reimplementation, but a &quot;transpilation&quot; of the psql source from C to JavaScript, makes this super interesting to me.<p><pre><code> From the Postgres master branch (17devel), we take exec_command_d, exec_command_list and exec_command_sf_sv from command.c, and all of describe.c and sql_help.c, from src&#x2F;bin&#x2F;psql. We use plenty of RegExp search-and-replace to turn this C code into valid JS syntax. We implement some C library functions, such as strlen and strchr, and some Postgres support functions, such as printTable and printQuery, in JavaScript. </code></pre> Read more here: <a href="https:&#x2F;&#x2F;neon.tech&#x2F;blog&#x2F;bringing-psqls-d-to-your-web-browser" rel="nofollow">https:&#x2F;&#x2F;neon.tech&#x2F;blog&#x2F;bringing-psqls-d-to-your-web-browser</a>
评论 #40301781 未加载
gmac大约 1 年前
OP and library author here. You’ll find the background to this in this blog post: <a href="https:&#x2F;&#x2F;neon.tech&#x2F;blog&#x2F;bringing-psqls-d-to-your-web-browser" rel="nofollow">https:&#x2F;&#x2F;neon.tech&#x2F;blog&#x2F;bringing-psqls-d-to-your-web-browser</a>
评论 #40305644 未加载
darby_eight大约 1 年前
This seems really cool, but also a nightmare to maintain. What are the plans for keeping this in sync with the upstream codebase?
评论 #40301349 未加载
评论 #40301327 未加载
stuaxo大约 1 年前
Thw convertet is nice, I could imagine it being it&#x27;s own library, with the generator, and a release including the generated code every postures release.
codesnik大约 1 年前
I&#x27;m not sure I understand how to use that.
评论 #40301370 未加载
评论 #40301091 未加载
redwood大约 1 年前
Anyone using Neon in prod? How is it?
antifa大约 1 年前
I wish \d allowed sorting alphabetically.