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

@guilhermeabreudev/capacitor-orm-sqlite

v1.9.1

Published

Gerenciado de sql e banco para sqlite no capacitor

Downloads

374

Readme

markdown

ORM SQLite para Capacitor

Este projeto é uma biblioteca ORM SQLite para uso com Capacitor, facilitando a integração e manipulação de bancos de dados SQLite em aplicativos móveis.

https://www.npmjs.com/package/@capacitor-community/sqlite

Instalação

Para instalar o pacote @guilhermeabreudev/capacitor-orm-sqlite, execute o seguinte comando:

npm install @guilhermeabreudev/capacitor-orm-sqlite
npx cap sync && npx cap copy

Configuração

  1. Adicionar o Plugin ao Projeto Adicione o plugin ao seu projeto Capacitor. Certifique-se de que o plugin está registrado corretamente.

Configurações de SQLite https://github.com/capacitor-community/sqlite/blob/master/README.md

Criação da conexão apenas uma única vez no arquivo inicial do seu projeto.

Angular: app-component.ts

new DatabaseConnectionOrmSQlite(
    new SQLiteConnection(CapacitorSQLite),
    'Nome do banco',
    'tipo de criptografia',
    'modo de criptografia',
    {{versão: number}},
    {{somenteLeitura: boolean}}
    {{MostrarSQlLog: boolean}}
)

o plugin ficará responsável por gerenciar todo a parte de conexão, com isso não se preocupe em abrir ou fechar uma nova conexão.

exemplo básico de usabilidade.


import { Column, EntityName, OneToMany } from '@guilhermeabreudev/capacitor-orm-sqlite';

@EntityName('Cliente') // nome da tabela 
export class Cliente implements ICliente { // class modelo

  //coluna do banco de dados
  @Column({
    primaryKey: true
  })
  public id!: number;

  @Column()
  public nome!: number;

  @Column()
  public descricao!: string;

  /**
   * Aqui fica um relacionamento entre tabela, nesse caso não pega 
   * para ativar o relacionamento e preciso no join passar a class modelo nos joins
   * mais a baixo terá um exemplo
  */
  @OneToMany()
  public carro: Carro[] | null = null;

  constructor(pCliente: Partial<ICliente>) {
    this.id = pCliente.id ?? this.id;
    this.nome = pCliente.nome ?? this.nome;
    this.descricao = pCliente.descricao ?? this.descricao;
    this.contexto = pCliente.contexto ?? this.contexto;
  }

}

import { Column, EntityName, ManyToOne } from '@guilhermeabreudev/capacitor-orm-sqlite';

@EntityName('Carro') // nome da tabela 
export class Carro implements ICarro { // class modelo

  //coluna do banco de dados
  @Column({
    primaryKey: true
  })
  public id!: number;

  @Column()
  public marca!: number;

  @Column()
  public placa!: string;

  @Column()
  public id_cliente!: string;

  /**
   * Aqui fica um relacionamento entre tabela, nesse caso não pega 
   * para ativar o relacionamento e preciso no join passar a class modelo nos joins
   * mais a baixo terá um exemplo
  */
  @ManyToOne()
  public cliente: IClient | null = null;

  constructor(oCarro: Partial<ICarro>) {
    this.id = oCarro.id ?? this.id;
    this.marca = oCarro.marca ?? this.marca;
    this.placa = oCarro.placa ?? this.placa;
  }

}

import { DatabaseConnectionOrmSQlite, QueryBuildOrmSQlite } from '@guilhermeabreudev/capacitor-orm-sqlite';


class ControladorClienteRepositorio  {
    public async salvar(clientes: Cliente | Cliente[]): Promise<Cliente[]> {
        return await DatabaseConnectionOrmSQlite.query(
        new QueryBuildOrmSQlite(Cliente)
        .insert(clientes)
        )
    }

    public async listarTodos(): Promise<Cliente[]> {
        const clientes = await DatabaseConnectionOrmSQlite.query<ICliente>(new QueryBuildOrmSQlite(Cliente).getQuery())

        return clientes.map(cliente => new Cliente(cliente))
    }

    public async listarComCarros(id: number): Promise<Cliente[]> {
        
    const clientesComCarros = await DatabaseConnectionOrmSQlite.query<ICliente>(
        new QueryBuildOrmSQlite(Cliente)
        .leftJoin(Carro, 'id', 'id_cliente', 'carros');
        .where('id', id);
        .getQuery()
    )

    return clientesComCarros.map(cliente => new Cliente(cliente))
  }
}

Lembrando que a tipagem e dinâmica logo, ao inserir a class o plugin se encarrega de ler todas as propriedade e com isso retornar tudo sem precisar ficar tentando lembrar o que está na class.

Também e possível realizar migrações do banco com o tipo IMigrationDatabaseOrmSQLite

DatabaseConnectionOrmSQlite.runMigrationsIfNeeded(MigrationDb)

Veja tudo em (https://github.com/GuilhermeAbreu/orm-sqlite/tree/main/docs)

Contribuição

Se você deseja contribuir para este projeto, por favor siga os seguintes passos:

Faça um fork do repositório.

Crie uma branch para suas alterações (git checkout -b minha-nova-feature).

Faça commit das suas alterações (git commit -am 'Adiciona nova feature').

Envie para o branch do repositório remoto (git push origin minha-nova-feature).

Abra um Pull Request para revisão.

Licença

Este projeto está licenciado sob a Licença MIT. Se precisar de mais ajustes ou detalhes, sinta-se à vontade para pedir!