1.1.1 • Published 2 months ago

oneci-polly v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Polly

Camada de abstração sobre o PostgreSQL


O objetivo deste pacote é facilitar o uso do banco Postegres em cenários sem ORM.

Polly gerencia o pool de conexões e abstrai os comandos de escrita (potencialmente mais perigosos), além de facilitar comandos de leitura.

Em breve no NPM. =D

Criador/mantenedor

  • Thiago Silva

Licença

  • MIT

Dependências

Polly depende apenas da biblioteca pg e usa a sintaxe básica do Typescript.

Modo de uso

O módulo /src/index.ts fornece basicamente toda a estrutura necessária para usar Polly. Você pode utilizar essa classe em qualquer lugar do seu código apenas fazendo:

const polly = getPolly();

// Inserir registro
const newID = await polly.insert({
    table: 'my_table',
    data: {
        name: 'Your name',
        age: 15
    },
    getID: true,
});

// Obter um registro
const result = await polly.getOne({
    query: 'SELECT * FROM my_table WHERE id = $1',
    params: [newID],
});

console.log(result);

// Deletar um registro
await polly.delete({
    table: 'my_table',
    where: 'id = $1',
    params: [newID]
})

Referências da API

Métodos Principais

Polly.select({
    query: string,
    params?: QueryParams, // Array com parâmetros
    limit?: number, // LIMIT clause
    skip?: number, // OFFSET clause
    orderBy?: string,
    orderByDesc?: boolean, // DESC if true
}): Promise<any[]>

Polly.insert({
    table: string,
    data: object | object[],
    getID?: boolean,
}): Promise<number | string | undefined>

Polly.update({
    table: string,
    data: object,
    where: string | null,
    params?: QueryParams,
}): Promise<void>

Polly.delete({
    table: string,
    where: string | null,
    params?: QueryParams,
}): Promise<void>

Polly.free(): void

Métodos auxiliares

Polly.getOne({
    query: string,
    params?: QueryParams,
    orderBy?: string,
    orderByDesc?: boolean,
}): Promise<object | null>

Polly.count({
    table: string,
    where?: string,
    pk?: string,
    params?: QueryParams
}): Promise<number>
1.1.1

2 months ago

1.1.0

2 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago

1.0.20

4 months ago

0.2.3

6 months ago

0.2.2

8 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.31

1 year ago

0.1.2

1 year ago

0.1.3

1 year ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.9

1 year ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago