Giter VIP home page Giter VIP logo

Comments (2)

dfahlander avatar dfahlander commented on June 3, 2024

No, there's no explicit change in the support for relations. However, dexie can be used that way anyway, just like with SQL with full consistency - it's just that one need to manage foreign keys consistency "manually". One way of doing that is to provide a service with methods to control deletion of objects. One can also use en entity class with methods to add and manage related entities.

Following the newly updated docs for using dexie with typescript

// SchoolClass.ts
export class SchoolClass extends Entity<AppDB> {
  class_id!: string;
  class_name!: string;

  delete() {
    return this.db.transaction('rw', db.classes, db.student_classes, db.instructor_classes, () => {
      db.student_classes.where({classId: this.class_id}).delete();
      db.instructor_classes.where({classId: this.class_id}).delete();
      db.classes.delete(this.class_id);
    });
  }
}

// Student.ts
export class Student extends Entity<AppDB> {
  student_id!: string;
  student_name!: string;

  delete() {
    return this.db.transaction('rw', db.students, db.student_classes, db.instructor_classes, () => {
      db.student_classes.where({student_id: this.student_id}).delete();
      db.instructor_classes.where({student_id: this.student_id}).delete();
      db.students.delete(this.student_id);
    });
  }
}

// AppDB.ts
export class AppDB extends Dexie {
  students!: EntityTable<Student, 'student_id'>;
  classes!: EntityTable<SchoolClass, 'class_id'>;
  ...
}

The point is, those operations that need to take care of managing related entities could be written in either a service method or an entity method. Other simpler operations, such as adding new entities or updating student_name etc might not need a service or entity method, but that is a matter of taste.

from dexie.js.

tacman avatar tacman commented on June 3, 2024

Thanks!

Some sort of native support for relational tables would be really cool. Of course, once you start down the rabbit hole of supporting "simple" joins you'd be asked to build a whole ORM.

from dexie.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.