Prisma 工作室
Prisma Studio 是数据库中数据的可视化编辑器。请注意,Prisma Studio 不是开源的,但你仍然可以在 prisma/studio
存储库中创建问题。
¥Prisma Studio is a visual editor for the data in your database. Note that Prisma Studio is not open source but you can still create issues in the prisma/studio
repo.
在终端中运行 npx prisma studio
。
¥Run npx prisma studio
in your terminal.
模型(表或集合)
¥Models (tables or collections)
首次打开 Prisma Studio 时,你将看到一个数据表布局,其中的侧边栏显示了 Prisma 模式文件中定义的所有模型的列表。
¥When you first open Prisma Studio, you will see a data table layout with a sidebar showing a list of all models defined in your Prisma schema file.
什么是型号?
¥What is a model?
术语模型是指添加到 Prisma 架构文件中的数据模型定义。根据你使用的数据库,模型定义(例如 model User
)是指关系数据库(PostgreSQL、MySQL、SQL Server、SQLite、CockroachDB)中的表或 MongoDB 中的集合。
有关详细信息,请参阅 定义模型。
¥The term model refers to the data model definitions that you add to the Prisma schema file. Depending on the database that you use, a model definition, such as model User
, refers to a table in a relational database (PostgreSQL, MySQL, SQL Server, SQLite, CockroachDB) or a collection in MongoDB.
For more information, see Defining models.
你可以选择一个模型,其数据会在新选项卡中打开。在此示例中,选择了 User
模型。
¥You can select a model and its data opens in a new tab. In this example, the User
model is selected.
打开和关闭模型
¥Open and close models
要打开另一个模型,请在侧边栏中找到该模型并单击它。
¥To open another model, locate the model in the sidebar and click on it.
要关闭模型,请单击模型选项卡中的 X 按钮。如果打开了多个模型,你也可以单击 "全部关闭" 关闭所有模型。
¥To close a model, click the the X button in the model tab. If there are multiple models open, you can also click "Close all" to close all models.
模型中数据类型的图标
¥Icons of data types in models
每个字段的数据类型用标题中的图标指示。
¥The data type for each field is indicated with an icon in the header.
下表列出了所有数据类型及其识别图标。
¥The table below lists all data types and their identifying icon.
字段数据类型 | 描述 |
---|---|
文本 | |
整数 | |
日期时间 | |
Boolean | |
预定义值列表(enum 数据类型) | |
另一个模型的相关记录列表 | |
{} 符号可以引用两种类型的字段之一。• 关系字段 • JSON 字段 |
模型中的键盘快捷键
¥Keyboard shortcuts in models
打开模型时,可以使用许多键盘快捷键来浏览和操作模型中的数据。
¥When you open a model, a number of keyboard shortcuts are available to browse and manipulate the data in the model.
Note
Prisma Studio 打开后,你可以通过在 macOS 上按 Cmd ⌘+/ 或在 Windows 上按 Ctrl+/ 打开键盘快捷键模式。
¥Note
With Prisma Studio open, you can open the keyboard shortcuts modal by pressing Cmd ⌘+/ on macOS or Ctrl+/ on Windows.
编辑数据
¥Edit data
Prisma Studio 提供了两种编辑现有数据的机制:内联编辑 和 侧面板编辑。
¥Prisma Studio offers two mechanisms for editing existing data: in-line editing and side panel editing.
在线编辑
¥In-line editing
要在线编辑数据,请双击单元格进入编辑模式。这样做会将光标放在单元格中并允许你编辑数据。数据可以复制并粘贴到单元格中。
¥To edit data in-line, double-click a cell to enter edit mode. Doing so will place your cursor in the cell and allow you to edit the data. Data can be copied and pasted into cells.
所有更改(添加、编辑或删除)必须经过确认才能生效。使用“保存更改”按钮确认添加和编辑的记录。当你选择记录并单击“删除记录”时,请在对话框中确认删除。
¥All changes (add, edit, or delete) must be confirmed before they will take effect. Confirm added and edited records with the Save change button. When you select records and click Delete records, confirm the deletion in a dialog box.
你可以累积多个添加的记录和编辑的单元格,然后可以使用“保存更改”按钮完成。
¥You can accumulate multiple added records and edited cells, which you can then finalize with the Save changes button.
编辑完数据后,单击绿色的“保存”按钮。
¥Once you have finished editing the data, click the green Save button.
批量编辑
¥Batch editing
可以一次编辑多条记录。双击任意单元格以编辑值,并根据需要移动到任何其他单元格。完成后,单击绿色的“保存”按钮。
¥Multiple records can be edited at once. Double click any cell to edit values, moving to any additional cells as necessary. Once complete, click the green Save button.
侧面板编辑
¥Side panel editing
Prisma Studio 还提供了一个用于编辑数据的侧面板。要打开侧面板,请单击位于每个可见记录最左侧的选择复选框旁边的编辑侧面板图标。
¥Prisma Studio also offers a side panel for editing data. To open the side panel, click the Edit side panel icon located beside the select checkbox at the far left of every visible record.
单击图标将打开右侧的侧面板,可以在其中执行编辑。完成后,单击侧面板外部,然后单击绿色的“保存”按钮以保存更改。
¥Clicking the icon will open the side panel on the right where edits can be performed. Once complete, click outside the side panel and click the green Save button to save the changes.
删除记录
¥Delete records
-
从左栏中,选中要删除的记录的复选框。
¥From the left column, select the check box for the records you want to delete.
-
单击删除 n 条记录。
¥Click Delete n record(s).
-
单击确认对话框中的“删除”。
¥Click Delete in the confirmation dialog.
你可以选择多条记录并使用“删除记录”按钮一次性删除它们。当你删除多条记录时,操作会立即完成(确认后)。
¥You can select multiple records and delete them at once with the Delete records button. When you delete multiple records, the operation completes immediately (after you confirm it).
此外,如果你有任何累积的添加或编辑记录,然后决定删除记录,则删除操作还会强制保存累积的编辑内容。
¥In addition, if you have any accumulated added or edited records and then decide to delete records, the deletion also force-saves the accumulated edits.
警告
删除记录是一项单独的操作,无法累积。如果你在删除记录时有未保存的编辑,则删除操作将首先强制保存未保存的编辑,然后完成。
¥Warning
Deleting a record is a separate operation that cannot be accumulated. If you delete a record while having unsaved edits, the delete operation first force-saves the unsaved edits and then completes.
你可以使用“放弃更改”按钮放弃任何累积的更改。
¥You can discard any accumulated changes with the Discard changes button.
复制和粘贴
¥Copy and paste
你可以使用以下方法复制任何表格单元格的值:
¥You can copy the value of any table cell using:
-
macOS 上的 Cmd ⌘ + C
¥Cmd ⌘ + C on macOS
-
Windows 上的 Ctrl + C
¥Ctrl + C on Windows
要粘贴到另一个单元格中,请首先双击该单元格进入编辑模式,然后使用:
¥To paste in another cell, first double-click the cell to enter edit mode, and then use:
-
macOS 上的 Cmd ⌘ + V
¥Cmd ⌘ + V on macOS
-
Windows 上的 Ctrl + V
¥Ctrl + V on Windows
添加一条记录
¥Add a record
-
在模型视图中,单击添加记录。
¥In the model view, click Add record.
-
根据每个字段中允许的数据,键入记录的数据。
¥Based on the data allowed in each field, type the data for the record.
字段数据类型 描述 文本 Integer
如果此类字段已预填充autoincrement()
,请不要编辑该单元格,也不要手动添加数字。日期时间
日期时间字段包含一长串数字、字母等。最佳做法是,复制另一个日期时间单元格的值并根据需要进行修改,然后再粘贴到字段中。布尔值
选择true
或false
。预定义列表
双击字段中的单元格并选择预定义选项之一。来自另一个模型的相关记录列表
它通常指数据库中另一个模型中存在的记录列表。如果你要添加新记录,并且相关模型中的记录尚不存在,则无需在当前模型中输入任何内容。{}
符号可以指代两种类型字段之一。
• 关系字段
• JSON 字段
与数据库中单独定义的模型的关系
通常需要选择与之前任何记录相同的值
单击模型名称查看 然后你可以为相关字段选择值的列表。
JSON 字段
双击该字段以编辑 JSON 数据。最佳实践是在验证器中验证编辑后的 JSON 数据并将其粘贴回单元格中。 -
(可选的)如果你对更改不满意,请单击放弃更改并重新开始。
¥(Optional) If you are unhappy with your changes, click Discard changes and start over.
-
单击保存 1 项更改。
¥Click Save 1 change.
过滤器
¥Filters
过滤数据
¥Filter data
使用“过滤器”菜单通过添加条件来过滤模型中的数据。
¥Use the Filters menu to filter data in the model by adding conditions.
在“过滤器”菜单中,添加的第一个条件是 where
子句。
¥In the Filters menu, the first condition that you add is the where
clause.
当你添加多个条件时,Prisma Studio 会过滤结果,以便所有条件组合应用。每个新条件都通过出现在前面的 and
运算符来指示这一点。
¥When you add multiple conditions, Prisma Studio filters the results so that all conditions apply in combination. Each new condition indicates this with the and
operator, which appears in front.
步骤
¥Steps
-
单击“过滤器”打开“过滤器”菜单。
¥Click Filters to open the Filters menu.
info信息Note
Click Filters again if you want to hide the menu. -
单击添加新过滤器。
¥Click Add a new filter.
-
配置条件。
¥Configure the condition.
-
选择你要筛选的字段。
¥Select the field by which you want to filter.
-
选择比较运算符。
¥Select a comparison operator.
-
equals
-
in
-
notin
-
lt
-
lte
-
gt
-
gte
-
not
-
-
输入要用于条件的值。
步骤结果:Prisma Studio 根据条件立即更新模型中的数据。¥Type the value you want to use for the condition.
Step result: Prisma Studio updates the data in the model immediately, based on the condition.
-
-
要添加新过滤器,请单击“添加新过滤器”并重复上述步骤。
¥To add a new filter, click Add a new filter and repeat the steps above.
-
要删除过滤器,请单击右侧的 x 按钮。
¥To remove a filter, click the x button on the right.
-
要删除所有过滤器,请单击全部清除。
¥To remove all filters, click Clear all.
结果
¥Result
-
模型中的数据是根据你添加的所有条件的组合进行过滤的。
¥The data in the model is filtered based on the combination of all conditions you add.
-
在“过滤器”菜单中,默认值“无”会更改以显示你添加的过滤器的数量。
¥In the Filters menu, the default value of None changes to display the number of filters you add.
显示和隐藏字段
¥Show and hide fields
你可以使用“字段”菜单选择要查看或隐藏的字段。
¥You can select which fields to view or hide by using the Fields menu.
什么是字段?
¥What is a field?
字段是你在 Prisma 架构文件的数据模型定义中添加的模型的属性。根据你使用的数据库,字段(例如 model User { title String }
中的 title
字段)是指关系数据库(PostgreSQL、MySQL、SQL Server、SQLite、CockroachDB)中的列或 MongoDB 中的文档字段。
了解更多信息 ,参见 定义字段。
¥A field is a property of a model which you add in the data model definitions in the Prisma schema file. Depending on the database that you use, a field, such as the title
field in model User { title String }
, refers to a column in a relational database (PostgreSQL, MySQL, SQL Server, SQLite, CockroachDB) or a document field in MongoDB.
For more information, see Defining fields.
步骤
¥Steps
-
单击“字段”菜单。
¥Click the Fields menu.
-
仅选择你想要查看的字段,并取消选择你想要隐藏的任何字段。
¥Select only the fields you want to see and deselect any fields you want to hide.
结果
¥Result
模型会立即被过滤,以隐藏你已取消选择的任何字段中的数据。
¥The model is immediately filtered to hide the data from any fields you have deselected.
此外,“字段”菜单还显示当前选择的字段数。
¥Also, the Fields menu shows the number of fields that are currently selected.
显示和隐藏记录
¥Show and hide records
你还可以选择在模型视图中显示或跳过特定数量的记录。
¥You can also select to show or skip a specific number of records in the model view.
什么是记录?
¥What is a record?
记录是指关系数据库(PostgreSQL、MySQL、SQL Server、SQLite、CockroachDB)中表中的一行数据或 MongoDB 中的文档。
¥A record refers to a row of data in a table in a relational database (PostgreSQL, MySQL, SQL Server, SQLite, CockroachDB) or a document in MongoDB.
步骤
¥Steps
-
单击“显示”菜单。
¥Click the Showing menu.
-
在“Take”框中,指定你希望模型视图显示的最大记录数。
¥In the Take box, specify the maximum number of records that you want the model view to show.
-
在“跳过”框中,指定要隐藏的第一条记录的数量。
¥In the Skip box, specify how many of the first records you want to hide.
结果
¥Result
该模型将立即根据你的选择进行过滤以显示或隐藏记录。
¥The model is immediately filtered to show or hide records based on your selection.
“显示”菜单指示模型中有多少可用记录,其中显示了多少条记录。
¥The Showing menu indicates how many records are shown out of how many available records are in the model.
对数据进行排序
¥Sort data
单击字段标题可按字段数据排序。
¥Click a field title to sort by the field data.
第一次单击按升序对数据进行排序,第二次单击按升序对数据进行排序 - 按降序排列。
¥The first click sorts the data in ascending order, the second - in descending order.
故障排除
¥Troubleshooting
终端:无法运行脚本/Prisma 客户端请求出错
¥Terminal: Failed to run script / Error in Prisma Client request
缓存问题可能会导致 Prisma Studio 使用旧版本的查询引擎。你可能会看到以下错误:
¥Caching issues may cause Prisma Studio to use an older version of the query engine. You may see the following error:
Error in request: PrismaClientKnownRequestError: Failed to validate the query Error occurred during query validation & transformation
要解决此问题,请删除以下文件夹:
¥To resolve, delete the following folders:
-
macOS 和 Linux 上的
~/.cache/prisma
¥
~/.cache/prisma
on macOS and Linux -
Windows 上的
%AppData%/Prisma/Studio
¥
%AppData%/Prisma/Studio
on Windows