@platformatic/sql-openapi
Advanced tools
Comparing version 0.9.2 to 0.10.0
{ | ||
"name": "@platformatic/sql-openapi", | ||
"version": "0.9.2", | ||
"version": "0.10.0", | ||
"description": "Map a SQL database to OpenAPI, for Fastify", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@platformatic/sql-mapper": "0.9.2", | ||
"@platformatic/sql-mapper": "0.10.0", | ||
"fastify": "^4.6.0", | ||
@@ -28,3 +28,3 @@ "mercurius": "^11.0.0", | ||
"dependencies": { | ||
"@platformatic/sql-json-schema-mapper": "0.9.2", | ||
"@platformatic/sql-json-schema-mapper": "0.10.0", | ||
"@fastify/deepmerge": "^1.1.0", | ||
@@ -31,0 +31,0 @@ "@fastify/swagger": "^8.0.0", |
@@ -30,11 +30,11 @@ | ||
CREATE TABLE owners ( | ||
id SERIAL PRIMARY KEY, | ||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(255) | ||
); | ||
CREATE TABLE posts ( | ||
id SERIAL PRIMARY KEY, | ||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(42), | ||
long_text TEXT, | ||
counter INTEGER, | ||
owner_id BIGINT UNSIGNED, | ||
owner_id INT UNSIGNED, | ||
FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE | ||
@@ -233,5 +233,5 @@ ); | ||
CREATE TABLE people ( | ||
id SERIAL PRIMARY KEY, | ||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
parent_id BIGINT UNSIGNED, | ||
parent_id INT UNSIGNED, | ||
FOREIGN KEY (parent_id) REFERENCES people(id) | ||
@@ -245,3 +245,3 @@ ); | ||
name VARCHAR(255) NOT NULL, | ||
parent_id BIGINT UNSIGNED, | ||
parent_id INTEGER UNSIGNED, | ||
FOREIGN KEY (parent_id) REFERENCES people(id) | ||
@@ -248,0 +248,0 @@ ); |
@@ -7,3 +7,3 @@ 'use strict' | ||
const sqlMapper = require('@platformatic/sql-mapper') | ||
const { clear, connInfo, isSQLite } = require('./helper') | ||
const { clear, connInfo, isSQLite, isMysql } = require('./helper') | ||
const { resolve } = require('path') | ||
@@ -33,2 +33,8 @@ const { test } = t | ||
);`) | ||
} else if (isMysql) { | ||
await db.query(sql`CREATE TABLE pages ( | ||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(42), | ||
counter INTEGER | ||
);`) | ||
} else { | ||
@@ -35,0 +41,0 @@ await db.query(sql`CREATE TABLE pages ( |
@@ -7,3 +7,3 @@ 'use strict' | ||
const fastify = require('fastify') | ||
const { clear, connInfo, isSQLite, isMariaDB, isPg, isMysql8 } = require('./helper') | ||
const { clear, connInfo, isSQLite, isMariaDB, isPg, isMysql8, isMysql } = require('./helper') | ||
const { resolve } = require('path') | ||
@@ -22,2 +22,7 @@ const { test } = t | ||
);`) | ||
} else if (isMysql) { | ||
await db.query(sql`CREATE TABLE pages ( | ||
id INT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, | ||
title VARCHAR(42) NOT NULL | ||
);`) | ||
} else { | ||
@@ -193,2 +198,7 @@ await db.query(sql`CREATE TABLE pages ( | ||
);`) | ||
} else if (isMysql) { | ||
await db.query(sql`CREATE TABLE pages ( | ||
id INT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, | ||
title VARCHAR(42) | ||
);`) | ||
} else { | ||
@@ -798,1 +808,103 @@ await db.query(sql`CREATE TABLE pages ( | ||
}) | ||
test('BIGINT', { skip: isSQLite }, async ({ pass, teardown, same, equal }) => { | ||
const app = fastify() | ||
app.register(sqlMapper, { | ||
...connInfo, | ||
async onDatabaseLoad (db, sql) { | ||
pass('onDatabaseLoad called') | ||
await clear(db, sql) | ||
await db.query(sql` | ||
CREATE TABLE simple_types ( | ||
id SERIAL PRIMARY KEY, | ||
counter BIGINT | ||
);`) | ||
} | ||
}) | ||
teardown(app.close.bind(app)) | ||
app.register(sqlOpenAPI) | ||
await app.ready() | ||
const counter = BigInt(Number.MAX_SAFE_INTEGER) + 1000n | ||
{ | ||
const res = await app.inject({ | ||
method: 'POST', | ||
url: '/simpleTypes', | ||
body: { | ||
id: 1, | ||
counter: counter.toString() | ||
} | ||
}) | ||
equal(res.statusCode, 200, 'POST /simpleTypes status code') | ||
same(res.json(), { | ||
id: 1, | ||
counter: counter.toString() | ||
}, 'POST /simpleTypes response') | ||
} | ||
{ | ||
const res = await app.inject({ | ||
method: 'GET', | ||
url: '/simpleTypes/1' | ||
}) | ||
equal(res.statusCode, 200, 'GET /simpleTypes status code') | ||
same(res.json(), { | ||
id: 1, | ||
counter: counter.toString() | ||
}, 'GET /simpleTypes response') | ||
} | ||
}) | ||
test('BIGINT as ids', { skip: isSQLite }, async ({ pass, teardown, same, equal }) => { | ||
const app = fastify() | ||
app.register(sqlMapper, { | ||
...connInfo, | ||
async onDatabaseLoad (db, sql) { | ||
pass('onDatabaseLoad called') | ||
await clear(db, sql) | ||
await db.query(sql` | ||
CREATE TABLE simple_types ( | ||
counter BIGINT PRIMARY KEY | ||
);`) | ||
} | ||
}) | ||
teardown(app.close.bind(app)) | ||
app.register(sqlOpenAPI) | ||
await app.ready() | ||
const counter = BigInt(Number.MAX_SAFE_INTEGER) + 1000n | ||
{ | ||
const res = await app.inject({ | ||
method: 'POST', | ||
url: '/simpleTypes', | ||
body: { | ||
counter: counter.toString() | ||
} | ||
}) | ||
equal(res.statusCode, 200, 'POST /simpleTypes status code') | ||
same(res.json(), { | ||
counter: counter.toString() | ||
}, 'POST /simpleTypes response') | ||
} | ||
{ | ||
const res = await app.inject({ | ||
method: 'GET', | ||
url: `/simpleTypes/${counter}` | ||
}) | ||
equal(res.statusCode, 200, 'GET /simpleTypes status code') | ||
same(res.json(), { | ||
counter: counter.toString() | ||
}, 'GET /simpleTypes response') | ||
} | ||
}) |
@@ -7,3 +7,3 @@ 'use strict' | ||
const sqlMapper = require('@platformatic/sql-mapper') | ||
const { clear, connInfo, isSQLite } = require('./helper') | ||
const { clear, connInfo, isSQLite, isMysql } = require('./helper') | ||
const { resolve } = require('path') | ||
@@ -34,2 +34,9 @@ const { test } = t | ||
);`) | ||
} else if (isMysql) { | ||
await db.query(sql`CREATE TABLE posts ( | ||
id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(42), | ||
long_text TEXT, | ||
counter INTEGER | ||
);`) | ||
} else { | ||
@@ -36,0 +43,0 @@ await db.query(sql`CREATE TABLE posts ( |
@@ -33,2 +33,9 @@ 'use strict' | ||
);`) | ||
} else if (isMysql) { | ||
await db.query(sql`CREATE TABLE posts ( | ||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(42), | ||
long_text TEXT, | ||
counter INTEGER | ||
);`) | ||
} else { | ||
@@ -337,11 +344,11 @@ await db.query(sql`CREATE TABLE posts ( | ||
CREATE TABLE owners ( | ||
id SERIAL PRIMARY KEY, | ||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(255) | ||
); | ||
CREATE TABLE posts ( | ||
id SERIAL PRIMARY KEY, | ||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(42), | ||
long_text TEXT, | ||
counter INTEGER, | ||
owner_id BIGINT UNSIGNED, | ||
owner_id INT UNSIGNED, | ||
FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE | ||
@@ -348,0 +355,0 @@ ); |
382463
13858
+ Added@platformatic/sql-json-schema-mapper@0.10.0(transitive)
- Removed@platformatic/sql-json-schema-mapper@0.9.2(transitive)