public async Task <TemplateResponse> GetTemplate(QueryRequest input) { var srcToken = "##SOURCE##"; var assmName = Guid.NewGuid().ToIdentifierWithPrefix("a"); var implName = Guid.NewGuid().ToIdentifierWithPrefix("UserCodeImpl"); var schemaResult = await _schemaService.GetSchemaSource(input.ConnectionString, input.ServerType, assmName, withUsings : false); var schemaSrc = schemaResult.Schema; var userText = input.Text ?? string.Empty; LinePosition tokenPos; var src = CodeTemplate .Replace("##NS##", assmName) .Replace("##DB##", "Proxy") .Replace("##SCHEMA##", schemaSrc) .Replace("##IMPLNAME##", implName) .ReplaceToken(srcToken, userText, out tokenPos); return(new TemplateResponse { Template = src, Namespace = assmName, LineOffset = tokenPos.Line, ColumnOffset = tokenPos.Character, DefaultQuery = string.Format("{0}.Take(100).Dump();{1}{1}", schemaResult.DefaultTable, Environment.NewLine) }); }
/// <summary> /// Returns the database context for the given connection string, /// optionally loading and compiling the types if missing. /// </summary> public async Task <CompileResult> GetDatabaseContext(string connectionString, DatabaseProviderType type) { if (!_map.ContainsKey(connectionString)) { var assmName = Guid.NewGuid().ToIdentifierWithPrefix("a"); var schemaResult = await _schemaService.GetSchemaSource(connectionString, type, assmName); if (schemaResult.Code != Api.StatusCode.Ok) { var errRes = new CompileResult { Code = schemaResult.Code }; return(errRes); } var result = _compileService.LoadType(schemaResult.Schema, assmName); _map.Add(connectionString, result); } return(_map[connectionString]); }