이 빠른 시작에서는 GitHub Copilot가 Visual Studio Code 내에서 직접 컨텍스트 인식 코드를 생성하여 SQL 및 ORM(개체 관계형 매핑) 개발을 가속화하는 방법을 알아봅니다. GitHub Copilot를 사용하면 테이블을 스캐폴드하고, 스키마를 발전시키고, 반복적인 스크립팅을 줄일 수 있습니다. T-SQL을 사용하든, Entity Framework, Sequelize, Prisma 또는 SQLAlchemy와 같은 ORM을 사용하든 관계없이 GitHub Copilot는 애플리케이션 논리 빌드에 집중할 수 있도록 도와줍니다.
시작하기
데이터베이스에 연결되어 있고 MSSQL 확장으로 활성 편집기 창이 열려 있는지 확인합니다. 이 연결을 사용하면 채팅 참가자가 @mssql 데이터베이스 환경의 컨텍스트를 이해할 수 있으므로 정확하고 컨텍스트 인식 제안을 사용할 수 있습니다. 데이터베이스 연결이 없으면 채팅 참가자는 의미 있는 응답을 제공하는 스키마 또는 데이터 컨텍스트가 없습니다.
다음 예제에서는 AdventureWorksLT2022 홈페이지에서 다운로드할 수 있는 샘플 데이터베이스를 사용합니다.
최상의 결과를 위해 사용자 고유의 환경에 맞게 테이블 및 스키마 이름을 조정합니다.
@mssql 접두사가 채팅에 포함되어 있는지 확인하세요. 예를 들어, @mssql을 입력한 후에 질문이나 프롬프트를 작성합니다. 이렇게 하면 채팅 참가자가 SQL 관련 지원을 요청하는 것을 이해할 수 있습니다.
GitHub Copilot를 사용하여 코드 생성
GitHub Copilot를 사용하여 연결된 데이터베이스의 구조를 반영하고 모범 사례를 따르는 SQL 및 ORM 호환 코드를 생성합니다. 테이블 및 관계 정의부터 스크립팅 뷰, 마이그레이션 파일 빌드 또는 데이터 액세스 계층 및 API 스캐폴딩에 이르기까지 GitHub Copilot는 더 빠르고 신뢰할 수 있는 이동을 지원합니다.
다음은 채팅 참가자를 통해 요청할 수 있는 일반적인 사용 사례 및 예제입니다.
SQL 코드 생성
GitHub Copilot는 스크립팅, 테이블 만들기 및 수정부터 저장 프로시저 및 뷰 작성에 이르기까지 여러 개발 시나리오에 대한 SQL 코드를 생성하는 데 도움이 될 수 있습니다. 이러한 예제에서는 GitHub Copilot를 사용하여 반복적인 SQL 스크립팅을 자동화하고 T-SQL 개발에 대한 모범 사례를 따르는 방법을 보여 줍니다.
스키마의 모든 테이블을 스크립트로 출력
Script out all the tables in the `SalesLT` schema as `CREATE TABLE` statements in SQL.
저장 프로시저를 사용하여 고객 데이터 검색
Write a SQL stored procedure in my current database. The procedure should retrieve all customers from the `SalesLT.Customer` table where the `LastName` matches a given parameter. Make sure to use T-SQL best practices.
모든 제약 조건 및 인덱스가 있는 테이블 스크립아웃
Script out the `SalesLT.Customer` table as a `CREATE TABLE` statement, including all constraints and indexes.
두 테이블을 조인하는 뷰를 스크립트로 생성하십시오.
Generate a SQL script to create a view that joins the `SalesLT.Customer` and `SalesLT.SalesOrderHeader` tables, showing customer names and their total order amounts.
새 열을 추가하여 테이블 변경
Write a SQL script to alter the `SalesLT.Customer` table by adding a `last_updated` column with a default timestamp.
ORM 마이그레이션 생성
GitHub Copilot는 스키마 컨텍스트 및 선택한 프레임워크에 따라 ORM 호환 마이그레이션 및 모델 정의를 생성할 수 있습니다. Sequelize에서 Entity Framework, Prisma 및 SQLAlchemy에 이르기까지 GitHub Copilot는 애플리케이션의 데이터 모델에 맞는 변경 내용을 스캐폴드하는 데 도움이 됩니다.
열을 추가할 모델 생성
Generate a Sequelize (JavaScript) model to add an `email` column (`varchar(256)`) to the `SalesLT.Customer` table.
Entity Framework 모델 클래스 생성
Generate an Entity Framework model class in C# to represent a `SalesLT.ProductModel` table with `id`, `name`, and `description` columns.
Entity Framework 모델 생성
Generate an Entity Framework model in C# based on the existing `SalesLT.Product` table.
Python 코드를 작성하여 테이블 정의
Write SQLAlchemy code to define a `SalesLT.OrderDetails` table with `id`, `order_date`, and `customer_id` fields, ensuring compatibility with `Python`.
매개 변수가 있는 쿼리 작성
Using SQLAlchemy, write a parameterized query that retrieves all customers from the `SalesLT.Customer` table where the `LastName` matches a provided parameter.
테이블을 추가하도록 기존 모델 업데이트
Update my existing Prisma model (schema.prisma) to define a new `SalesLT.Order` model with `id`, `customer_id`, and `order_date` fields.
테이블에 대한 모델 클래스 생성
Generate a SQLAlchemy model class for the `SalesLT.Product` table, including columns and data types.
기본 앱 코드 생성
또한 GitHub Copilot는 SQL 데이터베이스와 상호 작용하는 백 엔드 및 프런트 엔드 구성 요소를 스캐폴드하는 데 도움이 될 수 있습니다. 다음 예제에서는 Azure Functions, Node.js, Django 및 Next.js같은 인기 있는 스택을 사용하여 스키마에서 작업 애플리케이션 코드로 이동하는 방법을 보여 줍니다.
서버리스 백 엔드 SQL 바인딩 및 Blazor
다음 예제에서는 GitHub Copilot Chat과 함께 엔드투엔드 솔루션을 스캐폴드하는 데 사용할 수 있는 전체 프롬프트를 보여 줍니다. 이러한 프롬프트에는 Copilot가 백 엔드 및 프런트 엔드 계층 모두에서 정확하고 구조화된 코드를 생성하는 데 도움이 되는 자세한 지침과 컨텍스트가 포함됩니다.
Generate a full-stack app using Azure SQL bindings for Functions and Blazor WebAssembly. Follow these steps:
1. Backend: Azure Functions (C#) with SQL Bindings
- Configure SQL Bindings to automatically read and write data from the `SalesLT.Customer` table.
- Implement HTTP-triggered functions with the following endpoints:
- `GET /api/customers` – Fetch all customers.
- `GET /api/customers/{id}` – Get a specific customer by ID.
- `POST /api/customers` – Create a new customer.
- `PUT /api/customers/{id}` – Update an existing customer.
- `DELETE /api/customers/{id}` – Delete a customer.
- Use `Dependency Injection` for database connections and logging.
- Include an `appsettings.json` file to store database connection strings and environment variables.
- Use `Azure Functions Core Tools` to run and test the functions locally.
1. Frontend: Blazor WebAssembly (Optional)
- Create a Blazor WebAssembly frontend that consumes the API.
- Display a table with customer data and a form to add new customers.
- Use `HttpClient` to call the Azure Functions endpoints.
- Implement two-way data binding to handle form inputs dynamically.
- Use Bootstrap or Blazor components for styling and layout.
Ensure the project includes setup instructions for running both the Azure Functions backend and Blazor WebAssembly frontend locally, with proper `.env` or `local.settings.json` configurations for database connections.
Node.js와 Next.js를 사용하는 풀스택
다음 예제는 API 경로 및 데이터베이스 통합을 포함하여 전체 백 엔드 설정을 생성하기 위해 GitHub Copilot 채팅에서 제공할 수 있는 자세한 프롬프트입니다.
Generate a REST API using Node.js with Express that connects to my local SQL Database. Use the Tedious package for SQL Server connections and Prisma as the ORM. Follow these steps:
1. Backend: Node.js + Express
- Establish a database connection using Prisma with Tedious as the SQL Server driver.
- Implement API routes for `SalesLT.Customer` with the following endpoints:
- `GET /customers` – Fetch all customers.
- `GET /customers/:id` – Get a specific customer by ID.
- `POST /customers` – Create a new customer.
- `PUT /customers/:id` – Update an existing customer.
- `DELETE /customers/:id` – Delete a customer.
- Configure `Prisma` to map the `SalesLT.Customer` table and generate database migrations using `prisma migrate dev`.
- Use `dotenv` for environment variables (database credentials, ports, etc.).
- Add `Jest` for testing the API endpoints.
1. Frontend: Next.js + TypeScript (Optional)
- Create a Next.js frontend that consumes the API.
- Display a table with customer data and a form to add new customers.
- Use React hooks (`useState`, `useEffect`) to manage state and fetch data dynamically.
- Style the UI using Tailwind CSS.
- Implement server-side data fetching (`getServerSideProps`) in Next.js for improved performance.
Ensure the project includes setup instructions for running both the backend and frontend independently, with proper `.env` configurations for the database connection.
백 엔드: Django + Django REST 프레임워크
다음 예제는 API 경로 및 데이터베이스 통합을 포함하여 전체 백 엔드 설정을 생성하기 위해 GitHub Copilot 채팅에서 제공할 수 있는 자세한 프롬프트입니다.
Scaffold a Django backend with Django REST Framework for the `SalesLT.Customer` table. Follow these steps:
- Implement API routes using Django's `ModelViewSet` with the following endpoints:
- `GET /customers` – Fetch all customers.
- `GET /customers/{id}` – Get a specific customer by ID.
- `POST /customers` – Create a new customer.
- `PUT /customers/{id}` – Update an existing customer.
- `DELETE /customers/{id}` – Delete a customer.
- Add instructions for generating database migrations with `python manage.py makemigrations` and `migrate`.
사용자 경험 공유
MSSQL 확장에 대한 GitHub Copilot를 구체화하고 개선하는 데 도움이 되도록 다음 GitHub 문제 템플릿을 사용하여 피드백을 제출합니다. GitHub Copilot 피드백
피드백을 제출할 때 다음을 포함하는 것이 좋습니다.
테스트된 시나리오 – 스키마 만들기, 쿼리 생성, 보안, 지역화와 같이 집중한 영역을 알려주세요.
잘 작동하는 기능 – 원활하거나 도움이 되거나 예상을 초과한 모든 경험을 설명합니다.
문제 또는 버그 – 문제, 불일치 또는 혼란스러운 동작을 포함합니다. 스크린샷 또는 화면 녹화는 특히 유용합니다.
개선 제안 - 유용성 향상, 적용 범위 확장 또는 GitHub Copilot의 응답 향상을 위한 아이디어를 공유합니다.