Skip to content

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

@aflatoon2874

Description

@aflatoon2874

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 })

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions