Schema Definition
Thefiles table stores both files and folders in a hierarchical structure using a parent-child relationship.
Fields
Unique file/folder identifier
ID of the project this file belongs to
ID of the parent folder (undefined for root-level files)
File or folder name (e.g.,
"button.tsx", "components")File system entry type
Text file content (only for text files, undefined for folders and binary files)
Reference to binary file in Convex storage (only for binary files)
Unix timestamp (in milliseconds) of last update
Indexes
Index on
projectId for retrieving all files in a projectFields: ["projectId"]Index on
parentId for finding children of a folderFields: ["parentId"]Composite index for efficiently querying folder contents within a projectFields:
["projectId", "parentId"]Queries
getFiles
Retrieve all files and folders in a project.Project identifier
"Project not found"- Project doesn’t exist"Unauthorized to access this project"- User is not the owner
getFile
Retrieve a specific file or folder by ID.File identifier
"File not found"- File doesn’t exist"Project not found"- Associated project doesn’t exist"Unauthorized to access this project"- User is not the project owner
getFilePath
Get the full path to a file by traversing up the parent chain.File identifier
[{ _id: string, name: string }]
Use case: Building breadcrumb navigation (e.g., src > components > button.tsx)
Errors:
"File not found"- File doesn’t exist"Project not found"- Associated project doesn’t exist"Unauthorized to access this project"- User is not the project owner
getFolderContents
Get the direct children of a folder (or root-level files if no parent specified).Project identifier
Parent folder ID (omit for root-level files)
"Project not found"- Project doesn’t exist"Unauthorized to access this project"- User is not the owner
Mutations
createFile
Create a new text file.Project identifier
File name (e.g.,
"index.tsx")File content
Parent folder ID (omit for root level)
"Project not found"- Project doesn’t exist"Unauthorized to access this project"- User is not the owner"File already exists"- File with same name exists in this location
createFolder
Create a new folder.Project identifier
Folder name (e.g.,
"components")Parent folder ID (omit for root level)
"Project not found"- Project doesn’t exist"Unauthorized to access this project"- User is not the owner"Folder already exists"- Folder with same name exists in this location
updateFile
Update the content of a text file.File identifier
New file content
"File not found"- File doesn’t exist"Project not found"- Associated project doesn’t exist"Unauthorized to access this project"- User is not the project owner
renameFile
Rename a file or folder.File identifier
New name for the file or folder
"File not found"- File doesn’t exist"Project not found"- Associated project doesn’t exist"Unauthorized to access this project"- User is not the project owner"A file with this name already exists in this location"- Name conflict
deleteFile
Delete a file or folder. If deleting a folder, all descendants are recursively deleted.File identifier
- For files: Deletes the file and its storage reference (if binary)
- For folders: Recursively deletes all children before deleting the folder itself
"File not found"- File doesn’t exist"Project not found"- Associated project doesn’t exist"Unauthorized to access this project"- User is not the project owner
Source Reference
- Schema definition:
convex/schema.ts:33-44 - Queries and mutations:
convex/files.ts