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

Values of model is undefined and ID is not a string #346

Open sinux-l5d opened 2 years ago

sinux-l5d commented 2 years ago

Hi,

I'm trying DenoDB with a simple example : store users in a sqlite database.

But two issues occurs when inserting a user:

What am I missing ?

Minimal example :

class UserModel extends Model {
  static table = "users";
  static timestamps = true;

  id!: string;
  login!: string;
  password!: string;

  static fields = {
    id: { type: DataTypes.UUID, primaryKey: true },
    login: { type: DataTypes.STRING, length: 20, unique: true },
    password: DataTypes.string(128),
  };

  static defaults = {
    id: () => globalThis.crypto.randomUUID(),
  };
}

const connexion = new SQLite3Connector({
  filepath: "test.sqlite3",
});

const db = new Database(connexion);
db.link([UserModel]);
db.sync();

const userDB = await UserModel.create({
  login: "test",
  password: "test",
});

console.log(userDB);
/*
UserModel {
  id: undefined,
  login: undefined,
  password: undefined,
  affectedRows: 1,
  lastInsertId: 1
}
*/
sinux-l5d commented 2 years ago

Hi, so is it a bug, or a misunderstanding?