MCPcopy
hub / github.com/sequelize/sequelize / stuff

Function stuff

types/test/e2e/docs-example.ts:122–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120User.hasOne(Address,{sourceKey: 'id'});
121
122async function stuff() {
123 const newUser = await User.create({
124 name: 'Johnny',
125 preferredName: 'John',
126 });
127 console.log(newUser.id, newUser.name, newUser.preferredName);
128
129 const project = await newUser.createProject({
130 name: 'first!',
131 });
132
133 const ourUser = await User.findByPk(1, {
134 include: [User.associations.projects],
135 rejectOnEmpty: true, // Specifying true here removes `null` from the return type!
136 });
137 console.log(ourUser.projects![0].name); // Note the `!` null assertion since TS can't know if we included
138 // the model or not
139
140 const user = await sequelize.query('SELECT * FROM users WHERE name = :userName',{
141 type: QueryTypes.SELECT,
142 replacements: {
143 userName: 'Johnny'
144 },
145 mapToModel: true,
146 model: User
147 })
148}
149
150// Legacy models
151

Callers

nothing calls this directly

Calls 4

logMethod · 0.80
findByPkMethod · 0.80
createMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…