我对看起来像这样的自定义ORDER BY子句有要求
SELECT * FROM example
ORDER BY
CASE
WHEN name = 'I want this first' THEN 0
WHEN name = 'I want this second' THEN 1
WHEN name = 'We get the picture' THEN 2
ELSE 99 END ASC
Run Code Online (Sandbox Code Playgroud)
但是,此case语句已经增长,我希望能够将排序顺序重用于其他查询。
我看到我的选择是
在我看来,似乎我应该能够传递一个函数来执行排序逻辑。但是在SO和google上进行一些搜索后,我什么也找不到,并认为这也可能会帮助其他人。
我有一个使用来自自定义的哈希路由的Angular 4应用程序<base href="/long/required/path/index.html">。这样做是因为需求说明此url必须是项目的根。我正在尝试使用哈希路由来解决此问题。
我看到的问题涉及解析给定路线的数据。给定一个URLlocalhost:8000/long/require/path/index.html#/project/1/document/55
和 app.routes.ts
export const ROUTES: Routes = [
{
path: 'project/:projectId/document/:documentId',
component: DocumentViewerComponent,
resolve: { document: DataResolver}
},
{ path: '**', component: NoContentComponent }
];
Run Code Online (Sandbox Code Playgroud)
解析器在此处运行并按预期检索数据。
@Injectable()
export class DataResolver implements Resolve<Document> {
constructor(
private docService: DocumentService,
) { }
public resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Document> {
this.docService.getDocument(route.params.workspaceId,route.params.documentId)
.subscribe(d => {
console.log('Document received, waiting for components to load?', d);
this.docService.documentRecieved(d);
}
);
return this.docService.recievedDocument$;
}
}
Run Code Online (Sandbox Code Playgroud)
documentService
@Injectable()
export class DocumentService {
private …Run Code Online (Sandbox Code Playgroud)