> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # MSSQL 스토리지 MSSQL 스토리지 구현은 Microsoft SQL Server 데이터베이스를 사용하여 프로덕션에 즉시 사용 가능한 스토리지 솔루션을 제공합니다. ## 설치 **npm**: ```bash npm install @mastra/mssql@latest ``` **pnpm**: ```bash pnpm add @mastra/mssql@latest ``` **Yarn**: ```bash yarn add @mastra/mssql@latest ``` **Bun**: ```bash bun add @mastra/mssql@latest ``` ## 용법 ```typescript import { MSSQLStore } from '@mastra/mssql' const storage = new MSSQLStore({ id: 'mssql-storage', connectionString: process.env.DATABASE_URL, }) ``` ## 매개변수 **connectionString** (`string`): MSSQL 연결 문자열(예: Server=localhost,1433;Database=mydb;User Id=sa;Password=password;Encrypt=true;TrustServerCertificate=true) **schemaName** (`string`): 스토리지에서 사용할 스키마의 이름입니다. 제공하지 않으면 기본 스키마를 사용합니다. ## 생성자 예 다음과 같은 방법으로 `MSSQLStore`를 인스턴스화할 수 있습니다. ```ts import { MSSQLStore } from '@mastra/mssql' // Using a connection string only const store1 = new MSSQLStore({ id: 'mssql-storage-1', connectionString: 'Server=localhost,1433;Database=mydb;User Id=sa;Password=password;Encrypt=true;TrustServerCertificate=true', }) // Using a connection string with a custom schema name const store2 = new MSSQLStore({ id: 'mssql-storage-2', connectionString: 'Server=localhost,1433;Database=mydb;User Id=sa;Password=password;Encrypt=true;TrustServerCertificate=true', schemaName: 'custom_schema', // optional }) // Using individual connection parameters const store4 = new MSSQLStore({ id: 'mssql-storage-3', server: 'localhost', port: 1433, database: 'mydb', user: 'user', password: 'password', }) // Individual parameters with schemaName const store5 = new MSSQLStore({ id: 'mssql-storage-4', server: 'localhost', port: 1433, database: 'mydb', user: 'user', password: 'password', schemaName: 'custom_schema', // optional }) ``` ## 추가 참고사항 ### 스키마 관리 저장소 구현은 스키마 생성 및 업데이트를 자동으로 처리합니다. 다음 테이블이 생성됩니다. - `mastra_workflow_snapshot`: Workflow 상태 및 실행 데이터를 저장합니다. - `mastra_evals`: 평가 결과 및 메타데이터를 저장합니다. - `mastra_threads`: 대화 스레드를 저장합니다. - `mastra_messages`: 개별 메시지를 저장합니다. - `mastra_traces`: 원격 측정 및 추적 데이터를 저장합니다. - `mastra_scorers`: 점수 및 평가 데이터를 저장합니다. - `mastra_resources`: 자원 작업 Memory 데이터를 저장합니다. ### 초기화 스토리지를 Mastra 클래스에 전달하면 스토리지 작업 전에 `init()`이 자동으로 호출됩니다. ```typescript import { Mastra } from '@mastra/core' import { MSSQLStore } from '@mastra/mssql' const storage = new MSSQLStore({ connectionString: process.env.DATABASE_URL, }) const mastra = new Mastra({ storage, // init() is called automatically }) ``` Mastra 없이 저장소를 직접 사용하는 경우 테이블을 생성하려면 `init()`을 명시적으로 호출해야 합니다. ```typescript import { MSSQLStore } from '@mastra/mssql' const storage = new MSSQLStore({ id: 'mssql-storage', connectionString: process.env.DATABASE_URL, }) // Required when using storage directly await storage.init() // Access domain-specific stores via getStore() const memoryStore = await storage.getStore('memory') const thread = await memoryStore?.getThreadById({ threadId: '...' }) ``` > **경고:** `init()`을 호출하지 않으면 테이블이 생성되지 않으며, 저장소 작업이 아무런 오류 없이 실패하거나 오류가 발생합니다. ### 직접 데이터베이스 및 풀 액세스 `MSSQLStore`mssql 연결 풀을 공개 필드로 노출합니다. ```typescript store.pool // mssql connection pool instance ``` 직접 쿼리 및 사용자 정의 트랜잭션 관리를 지원합니다. 다음 필드를 사용하는 경우: - 적절한 연결 및 트랜잭션 처리는 사용자가 책임져야 합니다. - 저장소를 닫으면(`store.close()`) 연결된 연결 풀이 제거됩니다. - 직접 액세스하면 MSSQLStore 메서드가 제공하는 추가 로직이나 유효성 검사를 우회합니다. 이 접근 방식은 낮은 수준의 액세스가 필요한 고급 시나리오를 위한 것입니다.