Seed Query
New Seed Query Creation
The New Seed Query interface allows you to create, edit, and manage SQL queries such as SELECT
, INSERT
, UPDATE
, and DELETE
using a simple and intuitive interface. Additionally, it offers AI-assisted query generation to help streamline the query creation process.
AI-Generated Queries Using AI
The Generate Queries Using AI section allows you to leverage artificial intelligence to automatically generate SQL queries based on simple instructions and the context of the table you are working with. This feature streamlines the query creation process by reducing the need to manually write complex SQL syntax.
How it Works
By entering a natural language instruction or request in the Message Field, the AI interprets your message and generates a corresponding SQL query. This is especially useful for users who may not be familiar with SQL syntax or need to create queries quickly.
Message Field
The Message Field allows you to input a plain text instruction describing the type of query you need. The AI uses this input to generate a query based on the provided table's context (e.g., columns, data types).
-
Example 1: You want to retrieve all employees whose age is greater than 30. You would enter:
- Message: "Generate a query to select all employees whose age is greater than 30."
- AI Output:
SELECT * FROM employees WHERE age > 30;
-
Example 2: You want to fetch employee data for employees hired after 2020. You would enter:
- Message: "Generate a query to find all employees hired after January 1, 2020."
- AI Output:
SELECT * FROM employees WHERE hire_date > '2020-01-01';
Table Context
The Table Context dropdown allows you to select a table from the currently connected database. This context is crucial because it provides the AI with the schema information of the selected table, such as column names and their data types. The AI uses this schema to ensure that the queries generated are accurate and match the table structure.
- Example: If you select the
employees
table in the Table Context, the AI will generate queries based on the columns and data types defined in this table, such asid
,name
,age
, andhire_date
.
This feature ensures that the AI-generated query aligns with the selected table and prevents errors related to invalid column names or incorrect data types.
Similar Query
The Similar Query dropdown allows you to select existing queries that are similar to the one you are creating. This can help you reference or reuse previous queries, ensuring consistency and saving time.
- Example: If you previously created a query like
GetActiveEmployees
, you can select it from the Similar Query dropdown and use it as a reference to build a new query with slight modifications.
Send Button
Once you've provided a message in the Message Field, you can click the Send button to instruct the AI to generate a query based on your input. The AI will process the request and generate an SQL query that matches the intent of your instruction.
- Example: You enter the message "Generate a query to fetch all active employees." After clicking the Send button, the AI might generate the following query:
SELECT * FROM employees WHERE is_active = true;
-
Name:
- This field allows you to provide a name for your seed query. The name helps you identify and manage your queries easily.
- Example: You can name your query as
GetEmployeeData
,InsertNewEmployee
, etc.
-
Connection:
- The connection dropdown allows you to select the database where your query will be executed. In the provided image, the connection is set to
EmployeDetailsdbDevelopment
(MySQL). - This ensures that the query you are writing is linked to the appropriate database.
- The connection dropdown allows you to select the database where your query will be executed. In the provided image, the connection is set to
-
Query Type Tabs:
- Select: For writing
SELECT
queries to retrieve data from the database. - Insert: For writing
INSERT
queries to add new data to the database. - Update: For writing
UPDATE
queries to modify existing data in the database. - Delete: For writing
DELETE
queries to remove data from the database. - These tabs make it easier to switch between different types of queries and allow you to create the desired SQL operation based on your needs.
- Select: For writing
-
Code Editor:
- The main area is a code editor where you can manually write or edit your SQL queries.
- It supports syntax highlighting, which helps in reading and writing SQL code efficiently.
- Example: You can write a
SELECT * FROM employees;
query to retrieve all records from theemployees
table.
-
Params:
- This button lets you define input parameters for your query. Parameters allow you to write dynamic queries that take inputs during runtime.
- Example: For a query like
SELECT * FROM employees WHERE id = :employee_id;
, you can defineemployee_id
as a parameter.
-
Table Context:
- This field helps you understand the context of the table you are working with, providing essential metadata such as column names, types, and constraints.
- Example: If you are working with the
employees
table, the table context might show you details likeid (int)
,name (string)
,age (int)
, etc. - This is useful when writing queries, as it helps you avoid errors by ensuring you are working with the correct field names and types.
-
Save:
- Once you have finished creating or editing the query, click the Save button to store the query.
- This will save the query to the database or your local project, depending on your system setup.
-
Cancel:
- If you want to discard your changes and return to the previous screen without saving the query, click Cancel.
Example Seed Query Creation:
Query Name: GetActiveEmployees
- Connection: Select
EmployeDetailsdbDevelopment
(MySQL). - Query Type: Choose
SELECT
. - Query: Write the query in the code editor:
SELECT * FROM employees WHERE is_active = true;