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

Implement implicit transaction and locking in the context of redis-om for master-detail relations #66

Open
aflatoon2874 opened this issue Apr 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@aflatoon2874
Copy link

I am requesting a new feature to implement implicit transaction and locking in the context of redis-om for master-detail relations. Please see the code snippet below that illustrates the desired behaviour with enhanced schema definitions.

let albumSchema = new Schema(Album, {
  artist: { type: 'string' },
  title: { type: 'text' },
  year: { type: 'number' },
  genres: { type: 'string[]' },
  outOfPublication: { type: 'boolean' },
  studioId: { entity: 'Studio' } // 1-to-1 relation
})

let studioSchema = new Schema(Studio, {
  name: { type: 'string' },
  city: { type: 'string' },
  state: { type: 'string' },
  location: { type: 'point' },
  established: { type: 'date' },
  albums: { collection: 'Album', via: 'studioId' } // 1-to-m relation
})

let albumRepository = client.fetchRepository(albumSchema)
let studioRepository = client.fetchRepository(studioSchema)

// 1. 1-to-1 relation data persistence
let album = albumRepository.createEntity({
  artist: "Mushroomhead",
  title: "The Righteous & The Butterfly",
  year: 2014,
  genres: [ 'metal' ],
  outOfPublication: true
})

let studio = {
  name: "Bad Racket Recording Studio",
  city: "Cleveland",
  state: "Ohio",
  location: { longitude: -81.6764187, latitude: 41.5080462 },
  established: new Date('2010-12-27')
}

// Implement implicit transaction and locking
const { id, studioId } = albumRepository.save(album, { entity: 'Studio', data: studio })

// 2. 1-to-m relation data persistence
let albums = [{
  artist: "Mushroomhead",
  title: "Beautiful Stories for Ugly Children",
  year: 2010,
  genres: [ 'metal' ],
  outOfPublication: true
}, {
  artist: "Mushroomhead",
  title: "The Righteous & The Butterfly",
  year: 2014,
  genres: [ 'metal' ],
  outOfPublication: true
}]


let studio = studioRepository.createEntity({
  name: "Bad Racket Recording Studio",
  city: "Cleveland",
  state: "Ohio",
  location: { longitude: -81.6764187, latitude: 41.5080462 },
  established: new Date('2010-12-27')
})

// Implement implicit transaction and locking
const { id, albumIds } = studioRepository.save(studio, { collection: 'Album', data: albums })

@guyroyse guyroyse added the enhancement New feature or request label Aug 29, 2022
@asheghi
Copy link

asheghi commented Sep 5, 2022

relationships can be implemented the same way as mongoose implemented.

let albumSchema = new Schema(Album, {
  artist: { type: 'string' },
  title: { type: 'text' },
  year: { type: 'number' },
  genres: { type: 'string[]' },
  outOfPublication: { type: 'boolean' },
  studio: { type:'entityId', entity: 'Studio' } // 1-to-1 relation
  studios: { type:'entityId[]', entity: 'Studio' } // 1-to-m relation
})

relations can be stored as a new type entityId like mongoose used ObjectID for storing object reference.

@guyroyse
Copy link
Contributor

guyroyse commented Sep 6, 2022

I was envisioning something like this for embedded/related entities.

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

No branches or pull requests

3 participants