From e5a457ed9d643ed99b5adbb5626332235fb8a8ad Mon Sep 17 00:00:00 2001 From: Renee Tso <8248583+rtso@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:16:42 -0500 Subject: [PATCH] Defining an indexer data schema (#771) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description ![Screenshot 2025-01-15 at 5.06.34 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/vIwavW9noSx0eb70aDLz/e37ad4a5-027a-4a66-886c-5910b4bd522d.png) ### Checklist - If any existing pages were renamed or removed: - [x] Were redirects added to [next.config.mjs](../apps/nextra/next.config.mjs)? - [x] Did you update any relative links that pointed to the renamed / removed pages? - Do all Lints pass? - [x] Have you ran `pnpm fmt`? - [x] Have you ran `pnpm lint`? --- apps/nextra/next.config.mjs | 6 +++++ .../indexer-sdk/documentation/_meta.tsx | 3 +++ .../documentation/define-schema.mdx | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/define-schema.mdx diff --git a/apps/nextra/next.config.mjs b/apps/nextra/next.config.mjs index f075ce696..ca3ccc19b 100644 --- a/apps/nextra/next.config.mjs +++ b/apps/nextra/next.config.mjs @@ -407,6 +407,12 @@ export default withBundleAnalyzer( destination: "/en/build/indexer/indexer-sdk/documentation/setup", permanent: true, }, + { + source: "/indexer/indexer-sdk/documentation/define-schema", + destination: + "/en/build/indexer/indexer-sdk/documentation/define-schema", + permanent: true, + }, { source: "/indexer/indexer-sdk/documentation/create-processor", destination: diff --git a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/_meta.tsx b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/_meta.tsx index 2ea78a2d2..e1e57a819 100644 --- a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/_meta.tsx +++ b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/_meta.tsx @@ -1,5 +1,8 @@ export default { setup: { title: "Initial Setup" }, + "define-schema": { + title: "Defining a Data Schema", + }, "create-processor": { title: "Create a Processor", }, diff --git a/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/define-schema.mdx b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/define-schema.mdx new file mode 100644 index 000000000..95ee3ba61 --- /dev/null +++ b/apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/define-schema.mdx @@ -0,0 +1,26 @@ +--- +title: "Defining a Data Schema" +--- + +# Defining a Data Schema + +The first step with indexing is choosing a database and defining a schema for the data that you want to store. + +## Schema Considerations +When designing an indexer data schema, consider the following: +- Customizability: A schema serves as an interface for your dApp to access data tailored to your specific contract or application. +Ensure your schema is customized to meet your dApp's unique requirements. +- Query Optimization: A well-designed schema can enable more efficient data retrieval, supporting advanced operations such as aggregations, complex filtering, and table joins. +- Enhanced Performance: Schema design can significantly improve your dApp's performance. +By using the indexer, a single indexer query can often replace multiple queries to the fullnode. + +## Aptos Core Processors +All data exposed by the [Indexer API](../../aptos-hosted.mdx) is initially indexed using custom processors. +Each core processor indexes a specific type of data. +You can explore the [full list of processors](https://github.com/aptos-labs/aptos-indexer-processors/tree/main/rust/sdk-processor/src/processors) and the [complete indexer data schema](https://github.com/aptos-labs/aptos-indexer-processors/blob/main/rust/processor/src/db/postgres/schema.rs). + +The Aptos core processors and the [Quickstart Guide](../quickstart.mdx) use [PostgreSQL](https://www.postgresql.org/) as the database and [Diesel](https://diesel.rs/) as the ORM. +However, you are free to choose any database or ORM that fits your needs. +Popular alternatives include [SeaORM](https://www.sea-ql.org/SeaORM/) and [SQLx](https://github.com/launchbadge/sqlx). +Setting up a database and using an ORM is beyond the scope of these tutorials. +If you need guidance, refer to the tutorials linked above for more information.