1"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[782],{24384(e,n,t){t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"other-topics/indexes","title":"Indexes","description":"Sequelize supports adding indexes to the model definition which will be created on sequelize.sync().","source":"@site/versioned_docs/version-6.x.x/other-topics/indexes.md","sourceDirName":"other-topics","slug":"/other-topics/indexes","permalink":"/docs/v6/other-topics/indexes","draft":false,"unlisted":false,"editUrl":"https://github.com/sequelize/website/tree/main/versioned_docs/version-6.x.x/other-topics/indexes.md","tags":[],"version":"6.x.x","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1775795365000,"frontMatter":{"title":"Indexes"},"sidebar":"tutorialSidebar","previous":{"title":"Hooks","permalink":"/docs/v6/other-topics/hooks"},"next":{"title":"Working with Legacy Tables","permalink":"/docs/v6/other-topics/legacy"}}');var i=t(74848),o=t(28453);const r={title:"Indexes"},a=void 0,d={},l=[];function c(e){const n={a:"a",code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["Sequelize supports adding indexes to the model definition which will be created on ",(0,i.jsx)(n.a,{href:"pathname:///api/v6/class/src/sequelize.js~Sequelize.html#instance-method-sync",children:(0,i.jsx)(n.code,{children:"sequelize.sync()"})}),"."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-js",children:"const User = sequelize.define(\n 'User',\n {\n /* attributes */\n },\n {\n indexes: [\n // Create a unique index on email\n {\n unique: true,\n fields: ['email'],\n },\n\n // Creates a gin index on data with the jsonb_path_ops operator\n {\n fields: ['data'],\n using: 'gin',\n operator: 'jsonb_path_ops',\n },\n\n // By default index name will be [table]_[fields]\n // Creates a multi column partial index\n {\n name: 'public_by_author',\n fields: ['author', 'status'],\n where: {\n status: 'public',\n },\n },\n\n // A BTREE index with an ordered field\n {\n name: 'title_index',\n using: 'BTREE',\n fields: [\n 'author',\n {\n name: 'title',\n collate: 'en_US',\n order: 'DESC',\n length: 5,\n },\n ],\n },\n ],\n },\n);\n"})})]})}function u(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},28453(e,n,t){t.d(n,{R:()=>r,x:()=>a});var s=t(96540);const i={},o=s.createContext(i);function r(e){const n=s.useContext(o);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.