GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - types/sequelize: The typings for https://github.com/sequelize/sequelize

BranchesTags
Open more actions menu

Latest commit

 

History

206 Commits
206 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
lib
lib
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
.travis.yml
.travis.yml
 
 
README.md
README.md
 
 
docs_index.md
docs_index.md
 
 
index.d.ts
index.d.ts
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
tslint.json
tslint.json
 
 

Repository files navigation

Typescript Typings for Sequelize.

build dependencies devDependencies peerDependencies code style: prettier

API Documentation

Installation

npm install --save-dev types/sequelize#<commit hash>

Usage

import {
    Model,
    FindOptions,
    STRING,
    BelongsTo,
    BelongsToGetAssociationMixin,
    BelongsToSetAssociationMixin,
    BelongsToCreateAssociationMixin,
} from 'sequelize'
import { sequelize } from '../connection'

export class User extends Model {
    static associations: {
        group: BelongsTo
    }

    id: number
    username: string
    firstName: string
    lastName: string
    createdAt: Date
    updatedAt: Date

    // mixins for association (optional)
    groupId: number
    group: UserGroup
    getGroup: BelongsToGetAssociationMixin<UserGroup>
    setGroup: BelongsToSetAssociationMixin<UserGroup, number>
    createGroup: BelongsToCreateAssociationMixin<UserGroup>
}

User.init(
    {
        username: STRING,
        firstName: STRING,
        lastName: STRING,
    },
    { sequelize }
)

// associate
// it is important to import _after_ the model above is already exported so the circular reference works.
import { UserGroup } from './UserGroup'
User.belongsTo(UserGroup, { as: 'group', foreignKey: 'groupId' })
import { User, Group } from './models/User'

async function test() {
    const user = (await User.findOne({ include: [Group] })) as User
    user.firstName = 'John'
    await user.save()
    await user.setGroup(2)

    new User()
    new User({ firstName: 'John' })

    const user2 = (await User.create({ firstName: 'John', groupId: 1 })) as User
}

About

The typings for https://github.com/sequelize/sequelize

Topics

ormsequelizetypescripttypings

Resources

Readme
Activity
Custom properties

Stars

63 stars

Watchers

2 watching

Forks

35 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.