eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
https://eveningkid.com/denodb-docs
MIT License
1.93k stars 129 forks source link

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

Open SumitBando opened 3 years ago

SumitBando commented 3 years ago

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 }

jfranklin9000 commented 3 years ago

lastInsertId is the id.