npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlite-websql-orm

v1.2.1

Published

An orm for both sqlite and websql usable in Angular 2+ and Ionic 2+. [Follow us On Github](https://github.com/blixit/sqlite-websql-orm)

Downloads

5

Readme

SQLite-WebSQL-ORM

An orm for both sqlite and websql usable in Angular 2+ and Ionic 2+. Follow us On Github

1. Installation

npm i sqlite-websql-orm

:construction: This package is being updated to be compatible with angular 6. By the way many optimisations are done to improve the conceptual idea.

For Angular 4, node <8.9:

For Angular 6, node >=8.11, npm 6:

  • use versions above 1.2.1 : npm i [email protected]
  • the approach has been completely changed. Now you have different connectors (adapter) for each database (sqlite or websql). Using this approach, implementing IndexDb will be really easy

:warning: You will probably need to install manually some peer dependencies.

2. Usage & API

3. Known issues

If you get an issue please look first to the know issue or add an issue to our repository. docs/issues.md.

4. Changes from 0.2.2 to 1.0.0+

1. Configuration

  • Module name has changed from OrmModule to SqliteWebsqlOrmModule
  • UsefakeData has been replaced by adapter. Values of this configuration are define in ADAPTERS :
    • ADAPTERS.auto : let the module detect what connector/database use. The webSQL adapter will be tested before
    • ADAPTERS.sqlite : activate only the sqlite database
    • ADAPTERS.websql : activate only the websql database
// under vervion 0.2.2

imports: [
    // ...,
    OrmModule.init({
      name: 'my_custom_database.db',
      location: 'default',
      options: {
        useFakeDatabase: true,
        webname: 'my_custom_database',
        description: 'SQLite/WebSQL database for browser',
        version: '1.0',
        maxsize: 2 * 1024 * 1024
      }
    })
  ],

// above vervion 1.0.0, replace useFakeDatabase by adapter

import { SqliteWebsqlOrmModule, SchemaFactory, Manager, ADAPTERS } from 'sqlite-websql-orm';

imports: [
    // ...,
    SqliteWebsqlOrmModule.init({
      name: 'my_custom_database.db',
      location: 'default',
      options: {
        adapter: ADAPTERS.auto,
        webname: 'my_custom_database',
        description: 'SQLite/WebSQL database for browser',
        version: '1.0',
        maxsize: 2 * 1024 * 1024
      }
    })
  ],

2. Schema generation

  • Dont need to explicitly call RepositoryStore.getSchemaSources() anymore
// under vervion 0.2.2
export class AppModule {
  constructor(
    private schema: SchemaFactory,
    private platform: Platform,
  ) {
    if ( this.platform.is('mobile') ) {
      this.platform.ready().then(() => {
        this.generateSchema();
      }).catch(() => {
        console.log('mobile platform is not ready');
      });
    } else {
      this.generateSchema();
    }
  }

  generateSchema() {
    this.schema.generateSchema(RepositoryStore.getSchemaSources())   // <-- here 
    .then((db) => {
      console.log('Succeed to create the database');
      this.eventService.publish(EVENTS.database_schema_create);
    }).catch(() => {
      console.log('Failed to create the database');
      this.eventService.publish(EVENTS.database_schema_failure);
    });
  }
}

// above vervion 1.0.0, generateSchema doesnt take parameters anymore

generateSchema() {
    this.schema.generateSchema()  // <-- here 
    .then(async (connectionHandler) => {
      console.log('Succeed to create the database');
      this.events.publish('create');
    }).catch(() => {
      console.log('Failed to create the database');
      this.events.publish('failure');
    });
  }

 3. Repository

  • Defining the function mapArrayToObject() is not mandatory anymore.
  • By implementing this funciton, you are overrding the internal feature.
@Injectable()
@Repository(Personne)
export class PersonneRepository extends EntityRepository {
    constructor(public manager: Manager) {
        super(manager);
    }

    /**
     * In versions above 1.0.0,
     * this functions overrides the internal one. 
     */   
    mapArrayToObject(array: any): Personne {
        const personne: Personne = new Personne();
        personne.id = array.id;
        personne.name = array.name;

        return personne;
    }
}

The internal function looks like the function below. An instance of the class managed by the repository is created and all the fields are copied from the database array to the instance.

mapArrayToObject(array: Array<any>): EntityInterface {

    const instance = new (this.getClassToken());

    const schema = this.getSchema();

    for (const key in schema) {
      if (key) {
        const fieldMetadata = schema[key];
        instance[fieldMetadata.propertyKey] = array[fieldMetadata.name];
      }
    }

    return instance;
  }