# 存储过程

所有存储过程都位于应用的 `core` 架构中，返回 `VARIANT`，调用方式为 `CALL TOMBA.core.<procedure>(...)`。`VARIANT` 参数请传入对象（而非 JSON 字符串），例如 `{'domain': 'WEBSITE'}`。

## 对表运行的工具

| 存储过程                                                                                                                                                    | 功能                                                             | 角色         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------ |
| `find_emails(input_table STRING, domain_column STRING, first_name_column STRING, last_name_column STRING, output_table STRING, max_rows INT DEFAULT 100000)` | [对表运行 Email Finder](/snowflake/tools/email-finder)               | `app_public` |
| `verify_emails(input_table STRING, email_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                   | [对表运行 Email Verifier](/snowflake/tools/email-verifier)           | `app_public` |
| `search_domains(input_table STRING, domain_column STRING, output_table STRING, max_rows INT DEFAULT 100000, emails_per_domain INT DEFAULT 10)`               | [对表运行 Domain Search](/snowflake/tools/domain-search)             | `app_public` |
| `enrich_emails(input_table STRING, email_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                   | [对表运行 Email Enrichment](/snowflake/tools/email-enrichment)       | `app_public` |
| `enrich_people(input_table STRING, email_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                   | [对表运行 Person Enrichment](/snowflake/tools/person-enrichment)     | `app_public` |
| `enrich_companies(input_table STRING, domain_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                               | [对表运行 Company Enrichment](/snowflake/tools/company-enrichment)   | `app_public` |
| `enrich_combined(input_table STRING, email_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                 | [对表运行 Combined Enrichment](/snowflake/tools/combined-enrichment) | `app_public` |
| `find_emails_from_linkedin(input_table STRING, url_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                         | [对表运行 LinkedIn Finder](/snowflake/tools/linkedin-finder)         | `app_public` |
| `find_authors(input_table STRING, url_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                      | [对表运行 Author Finder](/snowflake/tools/author-finder)             | `app_public` |
| `find_phones(input_table STRING, email_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                                     | [对表运行 Phone Finder](/snowflake/tools/phone-finder)               | `app_public` |
| `validate_phones(input_table STRING, phone_column STRING, output_table STRING, max_rows INT DEFAULT 100000, country_code_column STRING DEFAULT '')`          | [对表运行 Phone Validator](/snowflake/tools/phone-validator)         | `app_public` |
| `find_similar_domains(input_table STRING, domain_column STRING, output_table STRING, max_rows INT DEFAULT 100000)`                                           | [对表运行 Similar Domains](/snowflake/tools/similar-domains)         | `app_public` |

## 对 1 个值运行的工具

| 存储过程                                                          | 功能                                                              | 角色         |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------- | ------------ |
| `email_finder(domain STRING, first_name STRING, last_name STRING)` | [对 1 个值运行 Email Finder](/snowflake/tools/email-finder)               | `app_public` |
| `email_verifier(email STRING)`                                     | [对 1 个值运行 Email Verifier](/snowflake/tools/email-verifier)           | `app_public` |
| `domain_search(domain STRING, emails_per_domain INT DEFAULT 10)`   | [对 1 个值运行 Domain Search](/snowflake/tools/domain-search)             | `app_public` |
| `email_enrichment(email STRING)`                                   | [对 1 个值运行 Email Enrichment](/snowflake/tools/email-enrichment)       | `app_public` |
| `person_enrichment(email STRING)`                                  | [对 1 个值运行 Person Enrichment](/snowflake/tools/person-enrichment)     | `app_public` |
| `company_enrichment(domain STRING)`                                | [对 1 个值运行 Company Enrichment](/snowflake/tools/company-enrichment)   | `app_public` |
| `combined_enrichment(email STRING)`                                | [对 1 个值运行 Combined Enrichment](/snowflake/tools/combined-enrichment) | `app_public` |
| `linkedin_finder(url STRING)`                                      | [对 1 个值运行 LinkedIn Finder](/snowflake/tools/linkedin-finder)         | `app_public` |
| `author_finder(url STRING)`                                        | [对 1 个值运行 Author Finder](/snowflake/tools/author-finder)             | `app_public` |
| `phone_finder(email STRING)`                                       | [对 1 个值运行 Phone Finder](/snowflake/tools/phone-finder)               | `app_public` |
| `phone_validator(phone STRING, country_code STRING DEFAULT '')`    | [对 1 个值运行 Phone Validator](/snowflake/tools/phone-validator)         | `app_public` |
| `similar_finder(domain STRING)`                                    | [对 1 个值运行 Similar Domains](/snowflake/tools/similar-domains)         | `app_public` |

## 任意工具

| 存储过程                                                                                                        | 功能                                                                                                   | 角色         |
| ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------ |
| `run_tool(tool STRING, input_table STRING, columns VARIANT, output_table STRING, max_rows INT, options VARIANT)` | [对表运行任意工具，可指定列映射和选项](/snowflake/enrich-a-table#other-input-combinations) | `app_public` |
| `lookup(tool STRING, params VARIANT)`                                                                            | 使用任意工具和输入执行 1 次查询                                                                            | `app_public` |
| `search_companies(filters VARIANT, output_table STRING, max_results INT DEFAULT 500)`                            | [将符合筛选条件的公司写入表](/snowflake/tools/companies-search)                                  | `app_public` |

## 后台运行与恢复

| 存储过程                                                                                                              | 功能                                                                          | 角色         |
| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------ |
| `run_tool_async(tool STRING, input_table STRING, columns VARIANT, output_table STRING, max_rows INT, options VARIANT)` | [在后台运行 `run_tool`；返回运行 ID](/snowflake/background-runs)        | `app_public` |
| `search_companies_async(filters VARIANT, output_table STRING, max_results INT DEFAULT 500)`                            | [在后台运行 `search_companies`](/snowflake/background-runs)                    | `app_public` |
| `cancel_run(run_id STRING)`                                                                                            | [停止正在运行或排队中的运行](/snowflake/background-runs#cancel)                     | `app_public` |
| `resume_run(run_id STRING)`                                                                                            | [继续已停止的运行](/snowflake/resume-and-auto-resume)                           | `app_public` |
| `set_auto_resume(run_id STRING, enabled BOOLEAN)`                                                                      | [为某次运行开启或关闭自动恢复](/snowflake/resume-and-auto-resume#auto-resume) | `app_public` |
| `resume_pending()`                                                                                                     | 立即恢复所有标记为自动恢复的运行（应用每天会自动执行）                   | `app_public` |
| `process_jobs()`                                                                                                       | 启动排队中的后台运行（应用会自动执行）                          | `app_public` |

## 计划任务

| 存储过程                                                                                                                           | 功能                                                     | 角色         |
| ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ------------ |
| `create_schedule(name STRING, tool STRING, input_table STRING, columns VARIANT, output_table STRING, cron STRING, options VARIANT)` | [按 CRON 计划持续丰富一张表](/snowflake/schedules) | `app_admin`  |
| `list_schedules()`                                                                                                                  | 计划任务及其最近一次运行                                     | `app_public` |
| `pause_schedule(name STRING)`                                                                                                       | 暂停计划任务                                                 | `app_admin`  |
| `resume_schedule(name STRING)`                                                                                                      | 重新启动已暂停的计划任务                                        | `app_admin`  |
| `run_schedule(name STRING)`                                                                                                         | 立即运行计划任务                                               | `app_public` |
| `drop_schedule(name STRING)`                                                                                                        | 删除计划任务（其表会保留）                              | `app_admin`  |

## 实用工具

| 存储过程                                | 功能                                                                              | 角色         |
| ---------------------------------------- | ----------------------------------------------------------------------------------------- | ------------ |
| `status()`                               | 应用版本、连接批准状态、试用、每日限制                                      | `app_public` |
| `list_tools()`                           | 所有工具及其输入、选项、积分和列                                  | `app_public` |
| `pricing()`                              | [每积分价格和各工具的积分消耗](/snowflake/pricing-and-limits)                    | `app_public` |
| `usage_summary(days INT DEFAULT 30)`     | [按天和工具统计的运行、积分和费用](/snowflake/results-and-history#usage-by-day) | `app_public` |
| `get_settings()`                         | [当前设置](/snowflake/reference/settings)                                         | `app_public` |
| `set_setting(name STRING, value STRING)` | [修改设置](/snowflake/reference/settings)                                         | `app_admin`  |
| `clear_cache(tool STRING DEFAULT '')`    | [清除某个工具的缓存结果（'' 表示全部）](/snowflake/cache-and-budgets)             | `app_admin`  |
| `drop_result(output_table STRING)`       | [删除结果表](/snowflake/results-and-history)                                     | `app_public` |
| `reset_credentials()`                    | 让应用在下次查询时重新连接 Tomba                                        | `app_admin`  |

视图：`TOMBA.core.runs`（所有运行）和 `TOMBA.core.usage_by_day`。请参阅[结果与历史记录](/snowflake/results-and-history)。
