Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ff00ff/mammoth

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ff00ff/mammoth - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

50

lib/__tests__/query.test.js

@@ -74,2 +74,9 @@ "use strict";

}());
var EnumTest = /** @class */ (function () {
function EnumTest() {
this.id = new columns_1.UuidColumn().primaryKey().default(new keywords_1.UuidGenerateV4());
this.value = new __1.EnumColumn(['a', 'b']).notNull();
}
return EnumTest;
}());
var db = pool_1.createDatabase({

@@ -80,5 +87,48 @@ account: new Account(),

binaryTest: new BinaryTest(),
enumTest: new EnumTest(),
});
describe('Query', function () {
afterAll(function () { return db.destroy(); });
describe('enum', function () {
beforeEach(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, db.exec("CREATE TYPE VALUE_ENUM AS ENUM ('a', 'b')")];
case 1:
_a.sent();
return [4 /*yield*/, db.exec("CREATE TABLE enum_test (\n id UUID PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),\n value VALUE_ENUM NOT NULL\n )")];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
afterEach(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, db.exec("DROP TABLE enum_test")];
case 1:
_a.sent();
return [4 /*yield*/, db.exec("DROP TYPE VALUE_ENUM")];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('should create row', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, db.insertInto(db.enumTest)
.values({
id: null,
value: 'a',
})];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
});
describe('bytea', function () {

@@ -85,0 +135,0 @@ beforeEach(function () { return db.exec("CREATE TABLE binary_test (\n id UUID PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),\n value BYTEA NOT NULL\n )"); });

6

lib/cli/migrations/generate.js

@@ -87,4 +87,6 @@ "use strict";

var table = db[tableName];
var query = table_1.generateCreateTableSql(table);
to.simulateQuery(query);
var queries = table_1.generateSql(table);
queries.forEach(function (query) {
to.simulateQuery(query);
});
});

@@ -91,0 +93,0 @@ return to;

@@ -81,3 +81,3 @@ /// <reference types="node" />

export declare class Column<T, IT = T | null, ST = T | null, UT = T> {
dataType: string;
dataType?: string;
type: T;

@@ -165,1 +165,5 @@ insertType: IT;

}
export declare class EnumColumn<A extends string, B extends string, C extends string | undefined, D extends string | undefined, E extends string | undefined, F extends string | undefined, G extends string | undefined, H extends string | undefined> extends Column<A | B | C | D | E | F | G | H> {
values: string[];
constructor(values: [A, B] | [A, B, C] | [A, B, C, D] | [A, B, C, D, E] | [A, B, C, D, E, F] | [A, B, C, D, E, F, G] | [A, B, C, D, E, F, G, H], name?: string);
}

@@ -468,2 +468,13 @@ "use strict";

exports.BinaryColumn = BinaryColumn;
var EnumColumn = /** @class */ (function (_super) {
__extends(EnumColumn, _super);
function EnumColumn(values, name) {
var _this = _super.call(this) || this;
_this.dataType = name;
_this.values = values;
return _this;
}
return EnumColumn;
}(Column));
exports.EnumColumn = EnumColumn;
//# sourceMappingURL=index.js.map

@@ -18,3 +18,3 @@ "use strict";

var table_2 = require("../table");
describe('generateCreateTableSql', function () {
describe('generate sql', function () {
it('should generate a simple table', function () {

@@ -37,3 +37,31 @@ var Organization = /** @class */ (function (_super) {

});
it('should generate a table with enum without name', function () {
var EnumTest = /** @class */ (function () {
function EnumTest() {
this.id = new columns_1.UuidColumn().primaryKey().notNull().default(new __1.UuidGenerateV4());
this.value = new columns_1.EnumColumn(["A", "B"]).notNull();
}
return EnumTest;
}());
var db = pool_1.createDatabase({
enumTest: new EnumTest(),
});
var sql = table_2.generateSql(db.enumTest);
expect(sql).toMatchSnapshot();
});
it('should generate a table with enum with name', function () {
var EnumTest = /** @class */ (function () {
function EnumTest() {
this.id = new columns_1.UuidColumn().primaryKey().notNull().default(new __1.UuidGenerateV4());
this.value = new columns_1.EnumColumn(["A", "B"], "MY_ENUM").notNull();
}
return EnumTest;
}());
var db = pool_1.createDatabase({
enumTest: new EnumTest(),
});
var sql = table_2.generateSql(db.enumTest);
expect(sql).toMatchSnapshot();
});
});
//# sourceMappingURL=table.test.js.map
import { TableWrapper } from '../table';
export declare const generateSql: <T extends TableWrapper<any, any, any>>(table: T) => string[];
export declare const generateTypeSql: <T extends TableWrapper<any, any, any>>(table: T) => string[];
export declare const generateCreateTableSql: <T extends TableWrapper<any, any, any>>(table: T) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var __1 = require("..");
// TODO: We could also immediately generate the AST from here?
exports.generateSql = function (table) {
return exports.generateTypeSql(table).concat([
exports.generateCreateTableSql(table),
]);
};
exports.generateTypeSql = function (table) {
return table.getColumns()
.filter(function (column) { return column.column instanceof __1.EnumColumn; })
.map(function (column) {
var enumColumn = column.column;
if (!enumColumn.dataType) {
enumColumn.dataType = (table.getName() + "_" + column.snakeCaseName + "_ENUM").toUpperCase();
}
return "CREATE TYPE " + enumColumn.dataType + " AS ENUM (" + enumColumn.values.map(function (value) { return "\"" + value + "\""; }).join(", ") + ")";
});
};
exports.generateCreateTableSql = function (table) {

@@ -5,0 +22,0 @@ var columns = table.getColumns().map(function (column) {

{
"name": "@ff00ff/mammoth",
"version": "0.6.0",
"version": "0.7.0",
"main": "./lib/index.js",

@@ -5,0 +5,0 @@ "types": "./lib/index.d.ts",

@@ -179,5 +179,32 @@ # Mammoth

const result = await db.sql `SELECT * FROM account WHERE account.name = ${name}`;
```
### Column data type
```
Class | Data type
-|-
TextColumn | TEXT |
CitextColumn | CITEXT
CaseInsensitiveTextColumn | CITEXT
IntegerColumn | INTEGER
DecimalColumn | DECIMAL
SerialColumn | SERIAL
JSONColumn<T> | JSON
JSONBColumn<T> | JSONB
TimestampWithTimeZoneColumn | TIMESTAMP WITH TIME ZONE
TimestampWithoutTimeZoneColumn | TIMESTAMP WITHOUT TIME ZONE
TimestampColumn | TIMESTAMP
DateColumn | DATE
TimeColumn | TIME
TimeWithoutTimeZoneColumn | TIME WITHOUT TIME ZONE
TimeWithTimeZoneColumn | TIME WITH TIME ZONE
IntervalColumn | INTERVAL
MoneyColumn | MONEY
UuidColumn | UUID
StringColumn | TextColumn
NumberColumn | IntegerColumn
ByteaColumn | BYTEA
BlobColumn | BYTEA
BinaryColumn | BYTEA
EnumColumn | *Creates an enum type*

@@ -184,0 +211,0 @@ ### Up next

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc