Author Archives: Andreas
Paperless-ngx installieren
Unter Portainer, auf Stacks und neuen Stack im Editor erstellen. Wichtig: Unter PAPERLESS_SECRET_KEY: XXX eine Zeichenkette generieren lassen.
SQL Server Datenbank Design -> Kroki ER Diagramm
https://kroki.io/examples.html#erd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
DECLARE @FlatTable TABLE ( TableName NVARCHAR(128), ColumnName NVARCHAR(128), DataType NVARCHAR(128), [MaxLength] INT, [Precision] INT, Scale INT, Nullable BIT, [Identity] BIT, PrimaryKey BIT, ForeignKeyName NVARCHAR(128), ParentTable NVARCHAR(128), ParentColumn NVARCHAR(128), ReferencedTable NVARCHAR(128), ReferencedColumn NVARCHAR(128) ); INSERT INTO @FlatTable SELECT tbl.[name] AS [TableName], col.[name] AS [ColumnName], ty.[name] AS [DataType], col.[max_length] AS [MaxLength], col.[precision] AS [Precision], col.[scale] AS [Scale], col.[is_nullable] AS [Nullable], col.[is_identity] AS [Identity], CONVERT(BIT, IIF(pkcol.index_id IS NOT NULL, 1, 0)) AS [PrimaryKey], fk.name AS ForeignKeyName, OBJECT_NAME(fk.parent_object_id) AS ParentTable, COL_NAME(fkc.parent_object_id, fkc.parent_column_id) AS ParentColumn, OBJECT_NAME(fk.referenced_object_id) AS ReferencedTable, COL_NAME(fkc.referenced_object_id, fkc.referenced_column_id) AS ReferencedColumn FROM sys.tables tbl INNER JOIN sys.columns col ON col.[object_id] = tbl.[object_id] INNER JOIN sys.types ty ON ty.[user_type_id] = col.[user_type_id] -- do not use system_type_id LEFT JOIN ( SELECT ind.[object_id] AS [table_object_id], ind.[index_id], ind.[column_id] FROM sys.index_columns ind INNER JOIN sys.key_constraints pks ON pks.[parent_object_id] = ind.[object_id] AND pks.[unique_index_id] = ind.[index_id] WHERE pks.[type] = 'PK' ) pkcol ON pkcol.[table_object_id] = tbl.[object_id] AND pkcol.[column_id] = col.[column_id] LEFT JOIN sys.foreign_key_columns fkc ON tbl.object_id = fkc.parent_object_id AND col.column_id = fkc.parent_column_id LEFT JOIN sys.foreign_keys fk ON fkc.constraint_object_id = fk.object_id WHERE 1=1 -- tbl.name does not start with __ AND tbl.name != '__RefactorLog' ORDER BY tbl.[name], CONVERT(BIT, IIF(pkcol.index_id IS NOT NULL, 1, 0)) DESC, fk.name DESC, col.[name]; DECLARE @StuffedTable TABLE (TableName NVARCHAR(128), Columns NVARCHAR(MAX)) INSERT INTO @StuffedTable SELECT TableName, STUFF ( ( SELECT ',' + CASE WHEN PrimaryKey = 1 THEN '*' WHEN ForeignKeyName IS NOT NULL THEN '+' ELSE '' END + ColumnName + ' ' + [DataType] + CASE WHEN [DataType] IN ('varchar','nvarchar') THEN ' (' + REPLACE(CONVERT(VARCHAR, [MaxLength]), '-1', 'max') + ')' WHEN [DataType] = 'decimal' THEN ' (' + CONVERT(VARCHAR, [Precision]) + ',' + CONVERT(VARCHAR, [Scale]) + ')' ELSE '' END FROM @FlatTable As T2 WHERE T2.TableName = T1.TableName FOR XML PATH (''), TYPE ).value('.', 'nvarchar(max)') , 1, 1, '') + ',' AS [Columns] FROM @FlatTable As T1 GROUP BY TableName DECLARE @ResultString NVARCHAR(MAX) = (SELECT STUFF ( ( SELECT ',' + '[' + TableName + ']' + ',' + Columns FROM @StuffedTable As T2 FOR XML PATH (''), TYPE ).value('.', 'nvarchar(max)') , 1, 1, '')) PRINT '```kroki' + CHAR(13) + CHAR(10) + 'erd' + CHAR(13) + CHAR(10) + REPLACE(@ResultString, ',', CHAR(13) + CHAR(10)) + '```' + CHAR(13) + CHAR(10) |
SQL Query um Tabellen und Spalten auszulesen inkl. PK und FK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
SELECT tbl.[name] AS [TableName], col.[name] AS [ColumnName], ty.[name] AS [DataType], col.[max_length] AS [MaxLength], col.[precision] AS [Precision], col.[scale] AS [Scale], col.[is_nullable] AS [Nullable], col.[is_identity] AS [Identity], CONVERT(BIT, IIF(pkcol.index_id IS NOT NULL, 1, 0)) AS [PrimaryKey], fk.name AS ForeignKeyName, OBJECT_NAME(fk.parent_object_id) AS ParentTable, COL_NAME(fkc.parent_object_id, fkc.parent_column_id) AS ParentColumn, OBJECT_NAME(fk.referenced_object_id) AS ReferencedTable, COL_NAME(fkc.referenced_object_id, fkc.referenced_column_id) AS ReferencedColumn FROM sys.tables tbl INNER JOIN sys.columns col ON col.[object_id] = tbl.[object_id] INNER JOIN sys.types ty ON ty.[user_type_id] = col.[user_type_id] -- do not use system_type_id LEFT JOIN ( SELECT ind.[object_id] AS [table_object_id], ind.[index_id], ind.[column_id] FROM sys.index_columns ind INNER JOIN sys.key_constraints pks ON pks.[parent_object_id] = ind.[object_id] AND pks.[unique_index_id] = ind.[index_id] WHERE pks.[type] = 'PK' ) pkcol ON pkcol.[table_object_id] = tbl.[object_id] AND pkcol.[column_id] = col.[column_id] LEFT JOIN sys.foreign_key_columns fkc ON tbl.object_id = fkc.parent_object_id AND col.column_id = fkc.parent_column_id LEFT JOIN sys.foreign_keys fk ON fkc.constraint_object_id = fk.object_id ORDER BY tbl.[name], col.[name]; |
Host oder Webhost mit Autofac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* Web: var builder = WebApplication.CreateBuilder(args); builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); */ var builder = Host.CreateDefaultBuilder() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { config .SetBasePath(System.IO.Directory.GetCurrentDirectory()) .AddJsonFile($"appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true) .AddJsonFile($"appsettings.{Environment.MachineName}.json", optional: true) .AddEnvironmentVariables(); }) .ConfigureServices((hostContext, services) => { IConfiguration config = hostContext.Configuration; Console.WriteLine(config.GetDebugView()); services.AddLogging(b => { b.AddDebug(); b.AddConsole(); }); // Register over IServiceCollection }) .ConfigureContainer<ContainerBuilder>(builder => { builder.RegisterInstance(new LoggerFactory()) .As<ILoggerFactory>(); builder.RegisterGeneric(typeof(Logger<>)) .As(typeof(ILogger<>)) .SingleInstance(); // Register over Autofac ContainerBuilder }); App = builder.Build(); var service = (AutofacServiceProvider)App.Services; this.Container = service.LifetimeScope; var myService = this.Container.Resolve<MyService>(); |
Entity Framework EF – Tabellen Models generieren lassen
Alt + T -> „NU“ eingeben
1 |
scaffold-DbContext "Server=XXX; Database=XXX; user id=sa; password = XXX;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir "Models\XXX" -Context XXXContext -Force -UseDatabaseNames -Tables XXX |
Windows Powershell Dienst einrichten
1 2 3 4 5 6 7 8 9 10 11 |
#Service installieren sc.exe create "Service Name" binpath="PathToService\MyService.exe" start= auto #Service starten sc.exe start "Service Name" #Service anhalten sc.exe stop "Service Name" #Service löschen sc.exe delete "Service Name" |
SQL Server Statistik IO und Time
1 2 3 4 5 6 7 |
SET STATISTICS IO ON SET STATISTICS TIME ON SELECT er.ReportID, er.ReportName, er.ReportNumber FROM dbo.EmployeeReports er WHERE er.ReportNumber LIKE '%33%' SET STATISTICS IO OFF SET STATISTICS TIME OFF |
Nuxt 3 mit Keycloak autorisieren
In diesem Beitrag will ich eine Schritt für Schritt Anleitung geben, wie man Nuxt 3 mit Keycloak autorisiert. Die Thematik um Autorisierung und Authentifizierung bedarf einer soliden Kenntnis in der Thematik. Ich empfehle daher unbedingt sich die Zeit zu nehmen und das folgende Video anzuschauen und sicher zu gehen, dass alles verstanden wurde:
Nuxt3 mit Vuetify 3 – Teil 3: Entwickeln in Vue / Typescript
Typescript muss in VS Code installiert werden. -g steht für globally (Alle Projekte)
1 |
npm i -g typescript |
Typescript Version prüfen
1 |
tsc --version |
Enums
Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut. |
Objekte werden mit reactive<type>({…}) reactiviert und primitive Datentypen mit ref<string>(…)
1 2 |
const myVariable = ref<string>("test"); const opel = reactive<myCar>({wheels: 4, name'Astra'}); |
Mixins werden in eine Vue Instanz hinzugefügt. So als würde man 2 Vue Instanzen verschmelzen. Composables sind dem ähnlich. In Mixins wird alles […]
Nuxt3 mit Vuetify 3 – Teil 2: Layout
Wenn man durch eine App navigiert, dann ist der Seitenaufbau überall identisch. Das Menü, die Kopfzeile und Fusszeile sind auf jeder Seite identisch. Lediglich der Inhalt ändert sich. In Nuxt 3 werden Layouts im „layouts“-Ordner erstellt und anschließend in die app.vue hinzugefügt. Einzelne Seiten werden im „pages“-Ordner erstellt. Nuxt 3 routet die pages anhand des […]
Login