eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

Home Page:https://eveningkid.com/denodb-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Values of model is undefined and ID is not a string

sinux-l5d opened this issue · comments

Hi,

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

But two issues occurs when inserting a user:

  • id is a number instead of a UUID
  • the values of the created model are undefined

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
}
*/

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