tspace-mysql
Version:
Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.
90 lines • 4.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = __importStar(require("chai"));
const mocha_1 = require("mocha");
const chai_json_schema_1 = __importDefault(require("chai-json-schema"));
const default_spec_1 = require("./default-spec");
const schema_spec_1 = require("./schema-spec");
const lib_1 = require("../lib");
chai_1.default.use(chai_json_schema_1.default);
(0, mocha_1.describe)('Testing Meta', function () {
/* ##################################################### */
(0, mocha_1.it)(`Meta: Start to get metadata from Model User with of assign schema`, async function () {
const metaUserWithOfSchema = (0, lib_1.Meta)(default_spec_1.User);
const table = metaUserWithOfSchema.table();
const column = metaUserWithOfSchema.column('id');
const columnRef = metaUserWithOfSchema.columnReference('id');
const columnTypeOf = metaUserWithOfSchema.columnTypeOf('id');
const columnType = metaUserWithOfSchema.columnType('id');
const columns = metaUserWithOfSchema.columns();
const hasColumn = metaUserWithOfSchema.hasColumn('id');
const primaryKey = metaUserWithOfSchema.primaryKey();
const indexes = metaUserWithOfSchema.indexes();
const nullable = metaUserWithOfSchema.nullable();
const defaults = metaUserWithOfSchema.defaults();
(0, chai_1.expect)(table).to.be.equal('users');
(0, chai_1.expect)(column).to.be.equal('id');
(0, chai_1.expect)(columnRef).to.be.equal('`users`.`id`');
(0, chai_1.expect)(columnTypeOf).to.be.equal(undefined);
(0, chai_1.expect)(columnType).to.be.equal(undefined);
(0, chai_1.expect)(columns).to.be.an('array');
(0, chai_1.expect)(hasColumn).to.be.equal(false);
(0, chai_1.expect)(primaryKey).to.be.equal(undefined);
(0, chai_1.expect)(indexes).to.be.an('array');
(0, chai_1.expect)(nullable).to.be.an('array');
(0, chai_1.expect)(defaults).to.be.equal(null);
});
(0, mocha_1.it)(`Meta: Start to get metadata from Model User with assign schema`, async function () {
const metaUserWithSchema = (0, lib_1.Meta)(schema_spec_1.User);
const table = metaUserWithSchema.table();
const column = metaUserWithSchema.column('id');
const columnRef = metaUserWithSchema.columnReference('id');
const columnTypeOf = metaUserWithSchema.columnTypeOf('id');
const columnType = metaUserWithSchema.columnType('id');
const columns = metaUserWithSchema.columns();
const hasColumn = metaUserWithSchema.hasColumn('id');
const primaryKey = metaUserWithSchema.primaryKey();
const indexes = metaUserWithSchema.indexes();
const nullable = metaUserWithSchema.nullable();
const defaults = metaUserWithSchema.defaults();
(0, chai_1.expect)(table).to.be.equal('users');
(0, chai_1.expect)(column).to.be.equal('id');
(0, chai_1.expect)(columnRef).to.be.equal('`users`.`id`');
(0, chai_1.expect)(columnTypeOf).to.be.equal('number');
(0, chai_1.expect)(columnType).to.be.equal('INT');
(0, chai_1.expect)(columns).to.be.an('array');
(0, chai_1.expect)(hasColumn).to.be.equal(true);
(0, chai_1.expect)(primaryKey).to.be.equal('id');
(0, chai_1.expect)(indexes).to.be.an('array');
(0, chai_1.expect)(nullable).to.be.an('array');
(0, chai_1.expect)(defaults).to.be.deep.equal({ status: 0 });
});
/* ###################################################### */
});
//# sourceMappingURL=06-Meta.test.js.map