ChildFileQuery generates query for child file(s) of a given set of root
(ownerID int, isSymbolic bool, root ...*ent.File)
| 116 | |
| 117 | // ChildFileQuery generates query for child file(s) of a given set of root |
| 118 | func (f *fileClient) childFileQuery(ownerID int, isSymbolic bool, root ...*ent.File) *ent.FileQuery { |
| 119 | rawQuery := f.client.File.Query() |
| 120 | if len(root) == 1 && root[0] != nil { |
| 121 | // Query children of one single root |
| 122 | rawQuery = f.client.File.QueryChildren(root[0]) |
| 123 | } else if root[0] == nil { |
| 124 | // Query orphan files with owner ID |
| 125 | predicates := []predicate.File{ |
| 126 | file.NameNEQ(RootFolderName), |
| 127 | } |
| 128 | |
| 129 | if ownerID > 0 { |
| 130 | predicates = append(predicates, file.OwnerIDEQ(ownerID)) |
| 131 | } |
| 132 | |
| 133 | if isSymbolic { |
| 134 | predicates = append(predicates, file.And(file.IsSymbolic(true), file.FileChildrenNotNil())) |
| 135 | } else { |
| 136 | predicates = append(predicates, file.Not(file.HasParent())) |
| 137 | } |
| 138 | |
| 139 | rawQuery = f.client.File.Query().Where( |
| 140 | file.And(predicates...), |
| 141 | ) |
| 142 | } else { |
| 143 | // Query children of multiple roots |
| 144 | rawQuery. |
| 145 | Where( |
| 146 | file.HasParentWith( |
| 147 | file.IDIn(lo.Map(root, func(item *ent.File, index int) int { |
| 148 | return item.ID |
| 149 | })...), |
| 150 | ), |
| 151 | ) |
| 152 | } |
| 153 | |
| 154 | return rawQuery |
| 155 | } |
| 156 | |
| 157 | // batchInCondition returns a list of predicates that divide original group into smaller ones |
| 158 | // to bypass DB limitations. |
no test coverage detected