Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit d47fb6a

Browse files
committed
initial commit
1 parent b437b0f commit d47fb6a

File tree

9 files changed

+888
-0
lines changed

9 files changed

+888
-0
lines changed

db/init.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE maps (
2+
title varchar(256) not null
3+
);

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "paradb-api",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"repository": "[email protected]:anonymousthing/paradb-api.git",
6+
"author": "D <[email protected]>",
7+
"license": "MIT",
8+
"scripts": {
9+
"start": "ts-node src/index.ts"
10+
},
11+
"devDependencies": {
12+
"@types/express": "^4.17.12",
13+
"@types/node": "^15.6.1",
14+
"@types/pg": "^8.6.0",
15+
"ts-node": "^10.0.0",
16+
"tsconfig-paths": "^3.9.0",
17+
"typescript": "^4.2.4"
18+
},
19+
"dependencies": {
20+
"express": "^4.17.1",
21+
"pg": "^8.6.0",
22+
"zapatos": "^3.6.0"
23+
}
24+
}

src/db/pool.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pg from 'pg';
2+
3+
const pool = new pg.Pool({ connectionString: 'postgresql://localhost/paradb' });
4+
pool.on('error', err => console.error(err));
5+
6+
export default pool;

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pool from 'db/pool';
2+
import express from 'express';
3+
import * as db from 'zapatos/db';
4+
5+
const port = 8081;
6+
const app = express();
7+
8+
app.get('/', async (req, res) => {
9+
const maps = await db.select('maps', db.all).run(pool);
10+
res.send(JSON.stringify(maps));
11+
});
12+
13+
app.listen(port, () => {
14+
console.log('Listening on 8081');
15+
});

src/zapatos/.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignorePatterns": [
3+
"*"
4+
]
5+
}

src/zapatos/schema.d.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
** DON'T EDIT THIS FILE **
3+
It's been generated by Zapatos (v3.6.0), and is liable to be overwritten
4+
5+
Zapatos: https://jawj.github.io/zapatos/
6+
Copyright (C) 2020 George MacKerron
7+
Released under the MIT licence: see LICENCE file
8+
*/
9+
10+
declare module 'zapatos/schema' {
11+
12+
import type * as db from 'zapatos/db';
13+
14+
// got a type error on schemaVersionCanary below? update by running `npx zapatos`
15+
export interface schemaVersionCanary extends db.SchemaVersionCanary { version: 101 }
16+
17+
/* === schema: public === */
18+
19+
/* --- enums --- */
20+
21+
22+
/* --- tables --- */
23+
24+
export namespace maps {
25+
export type Table = 'maps';
26+
export interface Selectable {
27+
/**
28+
* **maps.title**
29+
* - `varchar` in database
30+
* - `NOT NULL`, no default
31+
*/
32+
title: string;
33+
}
34+
export interface JSONSelectable {
35+
/**
36+
* **maps.title**
37+
* - `varchar` in database
38+
* - `NOT NULL`, no default
39+
*/
40+
title: string;
41+
}
42+
export interface Whereable {
43+
/**
44+
* **maps.title**
45+
* - `varchar` in database
46+
* - `NOT NULL`, no default
47+
*/
48+
title?: string | db.Parameter<string> | db.SQLFragment | db.ParentColumn | db.SQLFragment<any, string | db.Parameter<string> | db.SQLFragment | db.ParentColumn>;
49+
}
50+
export interface Insertable {
51+
/**
52+
* **maps.title**
53+
* - `varchar` in database
54+
* - `NOT NULL`, no default
55+
*/
56+
title: string | db.Parameter<string> | db.SQLFragment;
57+
}
58+
export interface Updatable {
59+
/**
60+
* **maps.title**
61+
* - `varchar` in database
62+
* - `NOT NULL`, no default
63+
*/
64+
title?: string | db.Parameter<string> | db.SQLFragment | db.SQLFragment<any, string | db.Parameter<string> | db.SQLFragment>;
65+
}
66+
export type UniqueIndex = never;
67+
export type Column = keyof Selectable;
68+
export type OnlyCols<T extends readonly Column[]> = Pick<Selectable, T[number]>;
69+
export type SQLExpression = db.GenericSQLExpression | db.ColumnNames<Updatable | (keyof Updatable)[]> | db.ColumnValues<Updatable> | Table | Whereable | Column;
70+
export type SQL = SQLExpression | SQLExpression[];
71+
}
72+
73+
/* === cross-table types === */
74+
75+
export type Table = maps.Table;
76+
export type Selectable = maps.Selectable;
77+
export type JSONSelectable = maps.JSONSelectable;
78+
export type Whereable = maps.Whereable;
79+
export type Insertable = maps.Insertable;
80+
export type Updatable = maps.Updatable;
81+
export type UniqueIndex = maps.UniqueIndex;
82+
export type Column = maps.Column;
83+
export type AllTables = [maps.Table];
84+
export type AllMaterializedViews = [];
85+
86+
87+
export type SelectableForTable<T extends Table> = {
88+
maps: maps.Selectable;
89+
}[T];
90+
91+
export type JSONSelectableForTable<T extends Table> = {
92+
maps: maps.JSONSelectable;
93+
}[T];
94+
95+
export type WhereableForTable<T extends Table> = {
96+
maps: maps.Whereable;
97+
}[T];
98+
99+
export type InsertableForTable<T extends Table> = {
100+
maps: maps.Insertable;
101+
}[T];
102+
103+
export type UpdatableForTable<T extends Table> = {
104+
maps: maps.Updatable;
105+
}[T];
106+
107+
export type UniqueIndexForTable<T extends Table> = {
108+
maps: maps.UniqueIndex;
109+
}[T];
110+
111+
export type ColumnForTable<T extends Table> = {
112+
maps: maps.Column;
113+
}[T];
114+
115+
export type SQLForTable<T extends Table> = {
116+
maps: maps.SQL;
117+
}[T];
118+
119+
}

tsconfig.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true,
4+
"esModuleInterop": true,
5+
"allowSyntheticDefaultImports": true,
6+
"lib": [
7+
"dom",
8+
"dom.iterable",
9+
"es2018",
10+
"es2019",
11+
"es2020",
12+
"esnext"
13+
],
14+
"moduleResolution": "node",
15+
"strict": true,
16+
"sourceMap": true,
17+
"baseUrl": "src",
18+
"target": "es6",
19+
"module": "commonjs",
20+
"rootDir": "src",
21+
"outDir": "dist"
22+
},
23+
"ts-node": {
24+
"require": ["tsconfig-paths/register"]
25+
},
26+
"include": [
27+
"src",
28+
]
29+
}

0 commit comments

Comments
 (0)