gpt4 book ai didi

sqlite - SQLite 中的简单书签管理器

转载 作者:行者123 更新时间:2023-12-03 17:17:59 29 4
gpt4 key购买 nike

我想准备一个简单的 SQLite 数据库来存储(标记)互联网书签,因为似乎没有简单的工具可以做到这一点。

我想我可以有三个表,一个用于 URL,另一个用于标签,另一个用于 URL 和标签之间的关系。

例如:

网址:

  • 1 : http://www.google.com/
  • 2 : http://maps.google.com/

  • 标签:
  • 1:谷歌
  • 2: map
  • 3:搜索

  • 关系:
  • 1:1:1
  • 1:1:3
  • 1:2:1
  • 1:2:2

  • 问题是我对 SQLite 的了解非常少,我发现检索所有带有“map”标签的 URL 的唯一方法是通过嵌套选择:
    select name from url where id=(
    select url_id from rel where tag_id=(
    select id from tag where name = 'map'
    )
    );

    手动存储书签也是一个无聊的操作。

    那么,有没有更有效的方法来实现这一点?

    谢谢你。

    最佳答案

    --
    -- URLs
    --
    CREATE TABLE urls (
    id INTEGER PRIMARY KEY,
    url TEXT NOT NULL
    );

    --
    -- Tags
    --
    CREATE TABLE tags (
    id INTEGER PRIMARY KEY,
    tag TEXT NOT NULL
    );

    --
    -- UrlTags
    --
    CREATE TABLE UrlTags (
    id INTEGER PRIMARY KEY,
    urls_id INTEGER,
    tags_id INTEGER,
    FOREIGN KEY(urls_id) REFERENCES url(id),
    FOREIGN KEY(tags_id) REFERENCES tags(id)
    );

    --
    -- URLS sample data
    --
    INSERT INTO urls VALUES (null, 'http://www.google.com/');
    INSERT INTO urls VALUES (null, 'http://maps.google.com/');

    --
    -- Tags sample data
    --
    INSERT INTO tags VALUES (null, 'google');
    INSERT INTO tags VALUES (null, 'map');
    INSERT INTO tags VALUES (null, 'search');

    --
    -- URLtags sample data
    -- Let's say http://www.google.com/ has all 3 tags
    INSERT INTO urltags VALUES (null, 1, 1);
    INSERT INTO urltags VALUES (null, 1, 2);
    INSERT INTO urltags VALUES (null, 1, 3);

    -- http://maps.google.com/ has only the 'map' tag
    INSERT INTO urltags VALUES (null, 2, 2);

    --- The following retrieves all urls associated with the 'search' tag
    --- which I assume will be only http://www.google.com/
    SELECT url
    FROM urls u INNER JOIN urltags r ON u.id = r.urls_id
    INNER JOIN tags t ON t.id = r.tags_id
    WHERE t.tag = 'search';

    关于sqlite - SQLite 中的简单书签管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6175924/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com