Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sinux-l5d opened this issue Jun 8, 2022 · 1 comment
Open

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

sinux-l5d opened this issue Jun 8, 2022 · 1 comment

Comments

@sinux-l5d
Copy link

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
}
*/
@sinux-l5d
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant