1.0.0-rc.54 • Published 3 years ago

@koober/database-client v1.0.0-rc.54

Weekly downloads
258
License
MIT
Repository
gitlab
Last release
3 years ago

Generic Database client (@koober/database-client)

NPM Version License

Database client library

Installation

npm install @koober/database-client

Usage

import { SQL, executeQuery, DatabaseClient } from '@koober/database-client';
import { runTask, Task } from '@koober/std';

interface User {
  id: number;
  name: string;
}

export function getUserById(client: DatabaseClient, id: User['id']) {
  const sqlStatement = SQL`SELECT id, name FROM user WHERE id=${id}`;
  const task = executeQuery(client, sqlStatement);

  return Task.map(task, (rows) => {
    return Array.isArray(rows) ? (rows[0] as User) : undefined;
  });
}

export async function main(): Promise<void> {
  const client: DatabaseClient = {
    databaseType: 'mysql',
    database: '',
    user: '',
  };

  const response = getUserById(client, 123);
  console.log(await runTask(response));
}

License

MIT © Julien Polo julien.polo@koober.com

1.0.0-rc.54

3 years ago

1.0.0-rc.53

3 years ago

1.0.0-rc.51

3 years ago

1.0.0-rc.50

3 years ago

1.0.0-rc.49

3 years ago

1.0.0-rc.48

3 years ago

1.0.0-rc.47

3 years ago

1.0.0-rc.46

3 years ago

1.0.0-rc.42

3 years ago

1.0.0-rc.45

3 years ago

1.0.0-rc.44

3 years ago

1.0.0-rc.43

3 years ago

1.0.0-rc.41

3 years ago

1.0.0-rc.40

3 years ago

1.0.0-rc.39

3 years ago

1.0.0-rc.38

3 years ago

1.0.0-rc.31

3 years ago

1.0.0-rc.30

3 years ago

1.0.0-rc.32

3 years ago

1.0.0-rc.28

3 years ago

1.0.0-rc.29

3 years ago

1.0.0-alpha.3

3 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago