Giter Club home page Giter Club logo

Comments (5)

gammelby avatar gammelby commented on June 15, 2024 2

I think ORM features are a bit overkill for something as conceptually simple as Ionic storage. Serialize to a blob and deserialize back again is sufficient, you don't care about the actual representation in storage. Just as how local storage (or Ionic storage) is typically used with JSON objects - with the addition of correctly marshalling class information so it can be cleanly used with TypeScript class instances.

from ionic-storage.

mhartington avatar mhartington commented on June 15, 2024 1

Closing for now.

from ionic-storage.

NoNameProvided avatar NoNameProvided commented on June 15, 2024

This would be pretty hard to do, as how would ionic-storage find out which class to use for deserialization? Also how it should react if something changes in the class definitions? This features sounds like a lot more like an userland feature.

A very basic implementation can be:

import { Storage } from '@ionic/storage';
import { deserialize } from "serializer.ts/Serializer";

export class CacheStorage {

  constructor(private storage: Storage) {
   
   }
  
  /**
   * Get the requested resource and cast it to the specified type.
   * @param key key identifying the requested resource
   * @param classType class of the requested resource
   * @returns Promise resolved with the value casted to the specified type
   */
  get<T>(key: string, classType: any): Promise<T> { 
    return this.storage.get(key).then( value => {
      return deserialize<T>(classType, value);  
    })
  }
}

from ionic-storage.

gammelby avatar gammelby commented on June 15, 2024

As for which class to use, the caller could specify the class name to use by the deserializer and then cast a general object returned.

I still think such out of the box support would make sense with ionic2 - the framework is based on TypeScript so you should be able to store TypeScript objects without any hassle (such as installing typings, installing serializer.ts, writing custom code).

from ionic-storage.

mlynch avatar mlynch commented on June 15, 2024

Some kind of ORM? Sounds interesting, not in the current scope or plans but will keep open to gather thoughts/opinions

from ionic-storage.

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.