问题描述
我想将目录(存在于磁盘上)存储到数据库中,维护它们的层次结构/树结构.
这是一个数字:
<前>(根)/目录 2 目录 3/ 目录 4 目录 5 目录 6/目录7我正在使用 SQLite 数据库.
请推荐我:
将上述结构存储在 SQLite 数据库中的 SQL 查询,以及
当我选择一个时检索目录完整路径的查询.
即假设我选择
Dir7
那么我应该得到像ROOT/Dir2/Dir4/Dir7
这样的完整路径
这是 SQLite 的快速闭包表示例.我没有包括将项目插入现有树的语句.相反,我只是手动创建了语句.您可以在分层数据模型幻灯片中找到插入和删除语句.
在为目录插入 ID 时,为了我的理智,我重命名了目录以匹配它们的 ID:
创建表格
将目录插入filesystem
表
创建闭包表路径
运行一些查询
I want to store the directories (present on the disk) into a database, maintaining their hierarchical/tree structure.
Here's a figure:
(ROOT) / Dir2 Dir3 / Dir4 Dir5 Dir6 / Dir7
I am using the SQLite database.
Please suggest me:
the SQL query to store above structure in SQLite database, and
a query to retrieve full path of the directory when I select one.
i.e. suppose I select
Dir7
then I should get the full path likeROOT/Dir2/Dir4/Dir7
Here's a quick closure table example for SQLite. I've not included the statements for inserting items into an existing tree. Instead, I've just created the statements manually. You can find the insert and delete statements in the Models for hierarchical data slides.
For the sake of my sanity when inserting the IDs for the directories, I renamed the directories to match their IDs:
Create tables
Insert directories into filesystem
table
Create the closure table paths
Run some queries
这篇关于文件系统中目录路径的分层/树数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!