denodb icon indicating copy to clipboard operation
denodb copied to clipboard

Model.create() return not documented. For MySQL, returns uninteresting { affectedRows: 1, lastInsertId: 1 }

Open SumitBando opened this issue 3 years ago • 1 comments

Similar to Issue #223

await Flight.create({ departure: "Paris", destination: "Tokyo" }); await Flight.create([{ ... }, { ... }]); ??? No specification of return value ???

Most frameworks will return either the Id from the database or the newly created model object.

MySQL driver is returning data of questionable value.

Test Program import { DataTypes, Model } from 'https://deno.land/x/denodb/mod.ts'; class Post extends Model { static table = 'posts'; static timestamps = true; static fields = { id: { primaryKey: true, autoIncrement: true }, username: {type: DataTypes.STRING /*, allowNull: false */}, body: {type: DataTypes.STRING}, }; static defaults = { }; } const post = await Post.create({username:'U', body:'B'}) console.log(post) Output: Post { affectedRows: 1, lastInsertId: 1 }

SumitBando avatar Jun 08 '21 17:06 SumitBando

lastInsertId is the id.

jfranklin9000 avatar Oct 10 '21 07:10 jfranklin9000