This functionality only works with data models written in JavaScript, not YAML.
This functionality only works with data models written in JavaScript, not YAML.
In Cube, your data model is code, and code is much easier to manage when it is
in small, digestible chunks. It is best practice to keep files small and
containing only relevant and non-duplicated code. As your data model grows,
maintaining and debugging is much easier with a well-organized codebase.Cube data models in JavaScript supports ES6-style export
and import statements, which allow writing code in one
file and sharing it, so it can be used by another file or files.There are several typical use cases in Cube where it is considered best practice
to extract some variables or functions and then import it when needed.
You can assign some commonly used SQL snippets to JavaScript functions. The
example below shows a parsing helper function, which can be used across any
number of cubes to correctly parse a date if it was stored as a string.You can read more about working with string time dimensions
here.
You may need to import from parent directories as Cube flattens nested
directories. The example below shows a correct way to import a helper function,
which is located in a parent directory.
// in model/sales/orders.jsimport { capitalize } from "./shared_utils/utils"
// in model/shared_utils/utils.jsexport const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1)
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Cube Documentation","colors":{"primary":"#5339CF","light":"#A5A3FF","dark":"#716EEE"},"logo":{"light":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/light.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=8bbf45ba64eac6116629064fac55aad7","dark":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/dark.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=d8fa230950c8c63b3c2f88d2768694d0"},"favicon":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/favicon.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=3b0cb7aa770d2abd546ef19463fbba8c","navbar":{"links":[{"href":"https://cube.dev/demos","label":"Demos"},{"href":"https://cube.dev/changelog","label":"Changelog"},{"href":"https://slack.cube.dev","label":"Community"}],"primary":{"type":"button","label":"Get Started","href":"https://cubecloud.dev/auth/signup"}},"footer":{"socials":{"x":"https://x.com/the_cube_dev","github":"https://github.com/cube-js/cube","linkedin":"https://www.linkedin.com/company/cube-dev"},"links":[{"header":"Legal","items":[{"label":"Privacy Policy","href":"https://cube.dev/legal/privacy-policy"},{"label":"Cookie Preferences","href":"#cookie-preferences"}]}]},"seo":{"metatags":{"og:type":"website","og:site_name":"Cube Documentation"},"indexing":"navigable"},"icons":{"library":"tabler"},"styling":{"codeblocks":"dark","latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cubed3","hasAudioNarration":false,"actualSubdomain":"cubed3","customDomains":["docs.cube.dev"],"gitSource":{"type":"github","owner":"cube-js","repo":"cube","deployBranch":"master","contentDirectory":"docs-mintlify","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6aef90e020a5c82e8b82b9df","clientVersion":"0.0.4088","searchFilterCounts":[{"language":"default","tag":"API","count":236},{"language":"default","tag":"Platform Endpoints","count":229},{"language":"default","tag":"Documentation","count":102},{"language":"default","tag":"Admin","count":95},{"language":"default","tag":"Data Modeling","count":65},{"language":"default","tag":"Recipes","count":47},{"language":"default","tag":"Topics","count":47},{"language":"default","tag":"Reference","count":44},{"language":"default","tag":"Connect to data","count":31},{"language":"default","tag":"Explore \u0026 Analyze","count":30}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"comment-mode","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#content-area table,.mdx-content table{width:100%!important}.cube-consent{position:fixed;right:16px;bottom:16px;z-index:2147483000;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;width:min(440px, calc(100vw - 32px));padding:16px;background:#fff;color:#111827;border:1px solid #e5e7eb;border-radius:8px;box-shadow:0 8px 24px rgb(0 0 0 / 12%);font-size:14px;line-height:1.5}html.dark .cube-consent{background:#111318;color:#f3f4f6;border-color:#2b2f38}.cube-consent__title{margin:0;padding-right:24px;font-size:16px;font-weight:600}.cube-consent__text,.cube-consent__status{margin:0;color:#4b5563}html.dark .cube-consent__text,html.dark .cube-consent__status{color:#b6bcc8}.cube-consent__link{color:inherit;text-decoration:underline}.cube-consent__actions{display:flex;gap:8px}.cube-consent__button{flex:1;padding:8px 16px;border:1px solid #111827;border-radius:6px;background:#111827;color:#fff;font:inherit;font-weight:500;cursor:pointer}html.dark .cube-consent__button{border-color:#f3f4f6;background:#f3f4f6;color:#111318}.cube-consent__button:hover{opacity:0.88}.cube-consent__button:focus-visible,.cube-consent__close:focus-visible,.cube-consent__link:focus-visible{outline:2px solid #111827;outline-offset:2px}html.dark .cube-consent :focus-visible{outline-color:#f3f4f6}.cube-consent__close{position:absolute;top:8px;right:8px;width:24px;height:24px;padding:0;border:0;background:transparent;color:inherit;font-size:20px;line-height:1;cursor:pointer}"}],"page":{"pagePath":"docs/data-modeling/dynamic/code-reusability-export-and-import","slug":"/docs/data-modeling/dynamic/code-reusability-export-and-import","pageMetadata":{"title":"Export and import","description":"This functionality only works with data models written in JavaScript, not YAML.","href":"/docs/data-modeling/dynamic/code-reusability-export-and-import"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"This functionality only works with data models written in JavaScript, not YAML.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,Heading,Info}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Info)_missingMdxReference(`Info`,true);return _jsxs(_Fragment,{children:[_jsx(Info,{children:_jsx(_components.p,{children:`This functionality only works with data models written in JavaScript, not YAML.`})}),`\n`,_jsx(_components.p,{children:`In Cube, your data model is code, and code is much easier to manage when it is\nin small, digestible chunks. It is best practice to keep files small and\ncontaining only relevant and non-duplicated code. As your data model grows,\nmaintaining and debugging is much easier with a well-organized codebase.`}),`\n`,_jsxs(_components.p,{children:[`Cube data models in JavaScript supports ES6-style `,_jsx(_components.a,{href:`https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export`,children:_jsx(_components.code,{children:`export`})}),`\nand `,_jsx(_components.a,{href:`https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import`,children:_jsx(_components.code,{children:`import`})}),` statements, which allow writing code in one\nfile and sharing it, so it can be used by another file or files.`]}),`\n`,_jsx(_components.p,{children:`There are several typical use cases in Cube where it is considered best practice\nto extract some variables or functions and then import it when needed.`}),`\n`,_jsx(Heading,{level:`2`,id:`managing-constants`,children:`Managing constants`}),`\n`,_jsxs(_components.p,{children:[`Quite often, you may want to have an array of test user IDs to exclude from your\nanalysis. You can define it once and `,_jsx(_components.code,{children:`export`}),` it like this:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in constants.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#4FC1FF`,\"--shiki-dark\":`#4FC1FF`},children:` TEST_USER_IDS`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` = [`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`2`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`4`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`]`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Later, you can `,_jsx(_components.code,{children:`import`}),` into the cube whenever needed:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`20`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in Users.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`TEST_USER_IDS`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"./constants\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`cube`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\"`users`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:` // ...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` measures:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:` // ...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` dimensions:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:` // ...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` segments:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` exclude_test_users:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` sql:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `\"}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#4FC1FF`,\"--shiki-dark\":`#4FC1FF`},children:`CUBE`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`.id NOT IN (`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#4FC1FF`,\"--shiki-dark\":`#4FC1FF`},children:`TEST_USER_IDS`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`join`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\", \"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\")`\"})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`helper-functions`,children:`Helper functions`}),`\n`,_jsx(_components.p,{children:`You can assign some commonly used SQL snippets to JavaScript functions. The\nexample below shows a parsing helper function, which can be used across any\nnumber of cubes to correctly parse a date if it was stored as a string.`}),`\n`,_jsxs(_components.p,{children:[`You can read more about working with `,_jsx(_components.a,{href:`/recipes/data-modeling/string-time-dimensions`,children:`string time dimensions\nhere`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`3`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in helpers.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:` parseDateWithTimeZone`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` = (`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`column`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`=>`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `PARSE_TIMESTAMP('%F %T %Ez', \"}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`column`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\")`\"})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`14`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in events.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`parseDateWithTimeZone`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"./helpers\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`cube`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\"`events`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` sql_table:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `events`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:` // ...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` dimensions:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` date:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` sql:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `\"}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`parseDateWithTimeZone`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"date\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` type:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `time`\"})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`import-from-parent-directories`,children:`Import from parent directories`}),`\n`,_jsx(_components.p,{children:`You may need to import from parent directories as Cube flattens nested\ndirectories. The example below shows a correct way to import a helper function,\nwhich is located in a parent directory.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`10`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── README.md`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── cube.js`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── package.json`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`└── model/`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ├── shared_utils/`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ └── utils.js`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` └── sales/`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` └── orders.js`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in model/sales/orders.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`capitalize`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"./shared_utils/utils\"`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6A9955`,\"--shiki-dark\":`#6A9955`},children:`// in model/shared_utils/utils.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:` capitalize`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` = (`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`s`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` s`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`charAt`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`toUpperCase`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`() + `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`s`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"dark","config":{},"pageMetadata":{"title":"Export and import","description":"This functionality only works with data models written in JavaScript, not YAML.","href":"/docs/data-modeling/dynamic/code-reusability-export-and-import"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Managing constants","slug":"managing-constants","depth":2,"children":[]},{"title":"Helper functions","slug":"helper-functions","depth":2,"children":[]},{"title":"Import from parent directories","slug":"import-from-parent-directories","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/cubed3/73c42f6b43b9b3b0/scripts/extract-chat.js","/_mintlify/custom/cubed3/19892615a6a53d32/scripts/extract-core-data.js","/_mintlify/custom/cubed3/476a9fa93e98d93b/consent.js"],"subdomain":"cubed3","siteName":"Cube Documentation","title":"Export and import - Cube Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-04-01T14:53:24.152Z","originalFileLocation":"docs/data-modeling/dynamic/code-reusability-export-and-import.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"This functionality only works with data models written in JavaScript, not YAML.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Cube Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Export and import - Cube Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"This functionality only works with data models written in JavaScript, not YAML.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Cube Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cubed3.mintlify.site/_mintlify/api/og/v2?division=Dynamic+Data+Models\u0026amp;title=Export+and+import\u0026amp;description=This+functionality+only+works+with+data+models+written+in+JavaScript%2C+not+YAML.\u0026amp;theme=784e8a91f0fc65e42d72e853\u0026amp;signature=44889add6ee767135ec6dd2fe3034dd411b5303bb4550db494b4e0cae707ab68\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Export and import - Cube Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"This functionality only works with data models written in JavaScript, not YAML.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cubed3.mintlify.site/_mintlify/api/og/v2?division=Dynamic+Data+Models\u0026amp;title=Export+and+import\u0026amp;description=This+functionality+only+works+with+data+models+written+in+JavaScript%2C+not+YAML.\u0026amp;theme=784e8a91f0fc65e42d72e853\u0026amp;signature=44889add6ee767135ec6dd2fe3034dd411b5303bb4550db494b4e0cae707ab68\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Cube Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#5339CF\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/data-modeling/dynamic/code-reusability-export-and-import.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.cube.dev/#organization\",\"name\":\"Cube Documentation\",\"url\":\"https://docs.cube.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/light.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=8bbf45ba64eac6116629064fac55aad7\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.cube.dev#website\",\"name\":\"Cube Documentation\",\"url\":\"https://docs.cube.dev\",\"publisher\":{\"@id\":\"https://docs.cube.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import#webpage\",\"url\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import\",\"name\":\"Export and import\",\"description\":\"This functionality only works with data models written in JavaScript, not YAML.\",\"dateModified\":\"2026-04-01T14:53:24.152Z\",\"isPartOf\":{\"@id\":\"https://docs.cube.dev#website\"},\"breadcrumb\":{\"@id\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Data Modeling\",\"item\":\"https://docs.cube.dev/docs/data-modeling/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamic Data Models\",\"item\":\"https://docs.cube.dev/docs/data-modeling/dynamic/index\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Export and import\",\"item\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import#article\",\"headline\":\"Export and import\",\"name\":\"Export and import\",\"description\":\"This functionality only works with data models written in JavaScript, not YAML.\",\"url\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import\",\"mainEntityOfPage\":{\"@id\":\"https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import#webpage\"},\"dateModified\":\"2026-04-01T14:53:24.152Z\",\"publisher\":{\"@id\":\"https://docs.cube.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.cube.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Cube Documentation\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Cube Documentation","nav":{"global":null,"tabs":[{"tab":"Documentation","groups":[{"group":"Getting Started","pages":[{"title":"Introduction","href":"/docs/introduction"},{"title":"Preferences","href":"/docs/preferences"},{"title":"Inbox","href":"/docs/inbox"},{"group":"Getting Started","pages":[{"title":"Connect your data","href":"/docs/getting-started/connect-your-data"},{"title":"Use analytics chat","href":"/docs/getting-started/use-analytics-chat"},{"title":"Create workbooks and dashboards","href":"/docs/getting-started/create-workbooks-and-dashboards"},{"title":"Develop in IDE","href":"/docs/getting-started/develop-in-ide"},{"title":"Embed analytics","href":"/docs/getting-started/embed-analytics"}]},{"group":"Migrate from Cube Core","pages":[{"title":"Import a local project to Cube Cloud with CLI","href":"/docs/getting-started/migrate-from-core/upload-with-cli"},{"title":"Import a GitHub repository","href":"/docs/getting-started/migrate-from-core/import-github-repository"},{"title":"Import a GitLab repository","href":"/docs/getting-started/migrate-from-core/import-gitlab-repository-via-ssh"},{"title":"Import a Git repository","href":"/docs/getting-started/migrate-from-core/import-git-repository-via-ssh"},{"title":"Import a Bitbucket repository","href":"/docs/getting-started/migrate-from-core/import-bitbucket-repository-via-ssh"}]}]},{"group":"Explore \u0026 Analyze","pages":[{"group":"Workbooks","root":{"title":"Workbooks","href":"/docs/explore-analyze/workbooks/index"},"pages":[{"title":"Querying data","href":"/docs/explore-analyze/workbooks/querying-data"},{"title":"Calculated fields","href":"/docs/explore-analyze/workbooks/calculated-fields"},{"title":"Source SQL Tabs","href":"/docs/explore-analyze/workbooks/source-sql-tabs"},{"title":"Python analysis","href":"/docs/explore-analyze/workbooks/python-analysis"},{"title":"Workbook Agent","href":"/docs/explore-analyze/workbooks/workbook-agent"}]},{"title":"Explore","href":"/docs/explore-analyze/explore"},{"group":"Charts","root":{"title":"Charts","href":"/docs/explore-analyze/charts/index"},"pages":[{"group":"Chart types","root":{"title":"Chart types","href":"/docs/explore-analyze/charts/chart-types/index"},"pages":[{"title":"Bar","href":"/docs/explore-analyze/charts/chart-types/bar"},{"title":"Line","href":"/docs/explore-analyze/charts/chart-types/line"},{"title":"Area","href":"/docs/explore-analyze/charts/chart-types/area"},{"title":"Scatter","href":"/docs/explore-analyze/charts/chart-types/scatter"},{"title":"Pie \u0026 donut","href":"/docs/explore-analyze/charts/chart-types/pie"},{"title":"Funnel","href":"/docs/explore-analyze/charts/chart-types/funnel"},{"title":"Sankey","href":"/docs/explore-analyze/charts/chart-types/sankey"},{"title":"Heatmap","href":"/docs/explore-analyze/charts/chart-types/heatmap"},{"title":"Boxplot","href":"/docs/explore-analyze/charts/chart-types/boxplot"},{"title":"Table","href":"/docs/explore-analyze/charts/chart-types/table"},{"title":"KPI","href":"/docs/explore-analyze/charts/chart-types/kpi"},{"title":"Map","href":"/docs/explore-analyze/charts/chart-types/map"},{"title":"HTML","href":"/docs/explore-analyze/charts/chart-types/html"}]},{"title":"Custom visualizations","href":"/docs/explore-analyze/charts/custom"},{"group":"Configure charts","root":{"title":"Configure charts","href":"/docs/explore-analyze/charts/configuration/index"},"pages":[{"title":"Series mapping","href":"/docs/explore-analyze/charts/configuration/series-mapping"},{"title":"Series configuration","href":"/docs/explore-analyze/charts/configuration/series-configuration"},{"title":"Color \u0026 stacking","href":"/docs/explore-analyze/charts/configuration/color-and-stacking"},{"title":"Small multiples","href":"/docs/explore-analyze/charts/configuration/small-multiples"},{"title":"Axes","href":"/docs/explore-analyze/charts/configuration/axes"},{"title":"Tooltips","href":"/docs/explore-analyze/charts/configuration/tooltips"},{"title":"Data labels","href":"/docs/explore-analyze/charts/configuration/data-labels"}]}]},{"title":"Analytics Chat","href":"/docs/explore-analyze/analytics-chat"},{"title":"Scheduled Tasks","href":"/docs/explore-analyze/scheduled-tasks"},{"title":"Agent skills","href":"/docs/explore-analyze/skills"}]},{"group":"Present \u0026 Share","pages":[{"group":"Dashboards","root":{"title":"Dashboards","href":"/docs/explore-analyze/dashboards/index"},"pages":[{"group":"Widgets","root":{"title":"Widgets","href":"/docs/explore-analyze/dashboards/widgets/index"},"pages":[{"title":"Charts","href":"/docs/explore-analyze/dashboards/widgets/charts"},{"title":"Text","href":"/docs/explore-analyze/dashboards/widgets/text"},{"title":"Controls","href":"/docs/explore-analyze/dashboards/widgets/controls"},{"title":"AI summary","href":"/docs/explore-analyze/dashboards/widgets/ai-summary"},{"title":"Spacer, Divider, Stack, Grid \u0026 Tabs","href":"/docs/explore-analyze/dashboards/widgets/layout"}]},{"title":"Cross-filtering","href":"/docs/explore-analyze/dashboards/cross-filtering"},{"title":"Styling","href":"/docs/explore-analyze/dashboards/styling"},{"title":"Dashboards as code","href":"/docs/explore-analyze/dashboards/dashboards-as-code"},{"title":"Dashboard Agent","href":"/docs/explore-analyze/dashboards/dashboard-agent"},{"title":"Comments","href":"/docs/explore-analyze/dashboards/comments"},{"title":"Reviews","href":"/docs/explore-analyze/dashboards/reviews"}]},{"title":"Apps","href":"/docs/explore-analyze/apps"},{"title":"Scheduled Refreshes","href":"/docs/explore-analyze/scheduled-refreshes"},{"title":"Data alerts","href":"/docs/explore-analyze/data-alerts"},{"title":"Google Sheets deliveries","href":"/docs/explore-analyze/google-sheets-deliveries"},{"title":"Notifications","href":"/docs/explore-analyze/notifications"}]},{"group":"Organize content","pages":[{"title":"Folders","href":"/docs/organize-content/folders"},{"title":"Share content","href":"/docs/organize-content/sharing"}]},{"group":"Data Modeling","pages":[{"title":"Getting started","href":"/docs/data-modeling/overview"},{"group":"Views","root":{"title":"Views","href":"/docs/data-modeling/views"},"pages":[{"title":"Multi-fact views","href":"/docs/data-modeling/multi-fact-views"},{"title":"View groups","href":"/docs/data-modeling/view-groups"}]},{"group":"Cubes","root":{"title":"Cubes","href":"/docs/data-modeling/cubes"},"pages":[{"title":"Extending cubes and views","href":"/docs/data-modeling/extending-cubes"}]},{"title":"Joins","href":"/docs/data-modeling/joins"},{"title":"Measures","href":"/docs/data-modeling/measures"},{"title":"Dimensions","href":"/docs/data-modeling/dimensions"},{"title":"Calendar cubes","href":"/docs/data-modeling/concepts/calendar-cubes"},{"title":"AI context","href":"/docs/data-modeling/ai-context"},{"title":"Syntax","href":"/docs/data-modeling/concepts/syntax"},{"group":"Access Control","pages":[{"title":"Access Control","sidebarTitle":"Overview","href":"/docs/data-modeling/access-control/index"},{"title":"Access policies","href":"/docs/data-modeling/data-access-policies"},{"title":"Row-level security","href":"/docs/data-modeling/access-control/row-level-security"},{"title":"Member-level security","href":"/docs/data-modeling/access-control/member-level-security"},{"title":"Security context","href":"/docs/data-modeling/access-control/context"}]},{"group":"Dynamic Data Models","root":{"title":"Dynamic Data Models","href":"/docs/data-modeling/dynamic/index"},"pages":[{"title":"Data modeling with YAML, Jinja, and Python","href":"/docs/data-modeling/dynamic/jinja"},{"title":"Data modeling with JavaScript","description":"This functionality only works with data models written in JavaScript, not YAML.","href":"/docs/data-modeling/dynamic/javascript"},{"title":"Export and import","href":"/docs/data-modeling/dynamic/code-reusability-export-and-import"},{"title":"Execution Environment (JavaScript)","description":"How JavaScript model code runs inside Cube’s Node VM, including custom require, forbidden globals, and constraints compared to normal Node scripts.","href":"/docs/data-modeling/dynamic/schema-execution-environment"}]},{"title":"Configuration","href":"/docs/data-modeling/configuration"},{"group":"Developing Model","pages":[{"title":"Visual Modeler","href":"/docs/data-modeling/visual-modeler"},{"title":"Data Model IDE","href":"/docs/data-modeling/data-model-ide"},{"title":"Development mode","href":"/docs/data-modeling/dev-mode"},{"title":"Access Policies viewer","href":"/docs/data-modeling/access-policies-viewer"},{"title":"Content Validator","href":"/docs/data-modeling/content-validator"}]}]},{"group":"Pre-aggregations","pages":[{"title":"Overview","href":"/docs/pre-aggregations/index"},{"title":"Getting started with pre-aggregations","href":"/docs/pre-aggregations/getting-started-pre-aggregations"},{"title":"Using pre-aggregations","href":"/docs/pre-aggregations/using-pre-aggregations"},{"title":"Matching queries with pre-aggregations","href":"/docs/pre-aggregations/matching-pre-aggregations"},{"title":"Refreshing pre-aggregations","href":"/docs/pre-aggregations/refreshing-pre-aggregations"},{"title":"Lambda pre-aggregations","href":"/docs/pre-aggregations/lambda-pre-aggregations"},{"title":"Cube Store architecture","href":"/docs/pre-aggregations/cube-store-architecture"}]},{"group":"Integrations","pages":[{"title":"Slack","href":"/docs/integrations/slack"},{"title":"Tableau Integration","sidebarTitle":"Tableau","hidden":true,"href":"/docs/integrations/tableau"},{"title":"Microsoft Power BI","hidden":true,"href":"/docs/integrations/power-bi/index"},{"title":"Cube for Excel","href":"/docs/integrations/microsoft-excel"},{"title":"Cube for Sheets","href":"/docs/integrations/google-sheets"},{"title":"Snowflake Semantic Views Integration","sidebarTitle":"Snowflake Semantic Views","href":"/docs/integrations/snowflake-semantic-views"},{"title":"Databricks Metric Views","href":"/docs/integrations/databricks-metric-views"},{"title":"Apache Ossie","href":"/docs/integrations/apache-ossie"},{"title":"dbt Integration","sidebarTitle":"dbt","href":"/docs/integrations/dbt"},{"group":"Semantic Layer Sync","root":{"title":"Semantic Layer Sync","hidden":true,"href":"/docs/integrations/semantic-layer-sync/index"},"pages":[{"title":"Semantic Layer Sync with Apache Superset","sidebarTitle":"Superset","hidden":true,"href":"/docs/integrations/semantic-layer-sync/superset"},{"title":"Semantic Layer Sync with Preset","sidebarTitle":"Preset","hidden":true,"href":"/docs/integrations/semantic-layer-sync/preset"},{"title":"Semantic Layer Sync with Tableau","sidebarTitle":"Tableau","hidden":true,"href":"/docs/integrations/semantic-layer-sync/tableau"}]},{"title":"MCP server","href":"/docs/integrations/mcp-server"},{"title":"Cube agent skills","href":"/docs/integrations/agent-skills"}]}]},{"tab":"Admin","pages":[{"title":"Admin","href":"/admin/connect-to-data"}]},{"tab":"Embedding","pages":[{"title":"Embedding","href":"/embedding"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/reference/data-modeling/cube"}]},{"tab":"Cube Core","pages":[{"title":"Cube Core","href":"/cube-core"}]},{"tab":"Recipes","pages":[{"title":"Recipes","href":"/recipes"}]},{"tab":"API","pages":[{"title":"API","href":"/api-reference/introduction"}]}]},"basePath":"","title":"Export and import - Cube Documentation","buildId":"dpl_DTau1J5HqS9UTgVSDwGksstFWtPa","deploymentId":"dpl_DTau1J5HqS9UTgVSDwGksstFWtPa","dynamics":[],"chunks":[]}