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

aca.ts

Package Overview
Dependencies
Maintainers
0
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aca.ts - npm Package Compare versions

Comparing version 0.0.92 to 0.0.93

1

dist/cli/create-client.js

@@ -49,2 +49,3 @@ "use strict";

process.chdir(acaRoot);
(0, child_process_1.execSync)(`npm config set registry https://registry.npmmirror.com/`);
(0, child_process_1.execSync)(`npx create-react-app ${name} --template typescript`);

@@ -51,0 +52,0 @@ const dbs = (await (0, orm_1.default)('.')).dbs;

43

dist/cli/up.js

@@ -246,7 +246,7 @@ "use strict";

}
async function betterSqlite3(acaDir, config, timestamp, currdb, prevDb) {
async function sqlite3(acaDir, config, timestamp, currdb, prevDb) {
const app = Object.keys(config.serverApps)[0];
if (!app)
throw new Error(`Need to create at least one server-side app, or add an app to register in config.json: aca add [dirname] -s`);
const sqlDiff = (0, sql_diff_1.default)('betterSqlite3');
const sqlDiff = (0, sql_diff_1.default)('sqlite3');
const connConf = process.env[currdb.config.connectOption.envConnect || ''] ||

@@ -259,10 +259,23 @@ currdb.config.connectOption.connect;

}
console.log(`Creating database tables...`);
console.log(`Creating database tables......`);
const db = sqlDiff.db.createSqliteDb(acaDir, config, connOption);
const allSql = (0, database_1.CreateAllTblSqls)(currdb.config, currdb.tables);
allSql.sqls =
sqlDiff.aca.create + sqlDiff.aca.insert(timestamp) + '\n' + allSql.sqls + ';';
sqlDiff.aca.create +
sqlDiff.aca.insert(timestamp) +
'\n' +
allSql.sqls +
';';
console.log(allSql.sqls);
try {
db.exec(allSql.sqls);
await new Promise((resolve, reject) => {
db.exec(allSql.sqls, function (err) {
if (err) {
reject(err);
}
else {
resolve(true);
}
});
});
db.close();

@@ -290,16 +303,20 @@ console.log(`Total: ${allSql.total} tables created successfully!`);

try {
await db.exec(allSqls);
await new Promise((resolve, reject) => {
db.exec(allSqls, function (err) {
if (err) {
reject(err);
}
else {
resolve(true);
}
});
});
}
catch (e) {
console.log(e);
throw e;
}
finally {
await db.close();
}
console.log(`Database(${connOption.filename}) updated successfully!`);
return allSqls;
}
else {
await db.close();
}
};

@@ -336,3 +353,3 @@ return await (prevDb ? AlterDb() : CreateDb());

mysql2,
betterSqlite3,
sqlite3,
}[dbs[k].config.connectOption.driver](acaDir, config, timestamp, dbs[k], prevDbs[k]);

@@ -339,0 +356,0 @@ rtn ? changed.push(`### ${k}:\n\`\`\`\n${rtn}`) : '';

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

}
if (config.connectOption.driver === 'betterSqlite3') {
if (config.connectOption.driver === 'sqlite3') {
rtn.create.push(sqlDiff.tbl(tbls[jsName].dbName).create(create.concat(foreigns).join(',\n')));

@@ -141,4 +141,4 @@ rtn.alter.push(uniques.join(';\n\n'));

if (constraint) {
if (config.connectOption.driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改外键');
if (config.connectOption.driver === 'sqlite3') {
throw new Error('sqlite3 暂不支持修改外键');
}

@@ -164,4 +164,4 @@ rtn.alter.push(constraint);

if (constraint) {
if (config.connectOption.driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改外键');
if (config.connectOption.driver === 'sqlite3') {
throw new Error('sqlite3 暂不支持修改外键');
}

@@ -264,4 +264,4 @@ rtn.alter.push(constraint);

if (alterCol.props.foreign && config.foreignKeyConstraint) {
if (config.connectOption.driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改外键');
if (config.connectOption.driver === 'sqlite3') {
throw new Error('sqlite3 暂不支持修改外键');
}

@@ -472,3 +472,3 @@ if (alterCol.props.foreign.old) {

if (diff.alterView[k].map) {
if (currdb.config.connectOption.driver === 'betterSqlite3') {
if (currdb.config.connectOption.driver === 'sqlite3') {
rtn.alter.push(`DROP VIEW IF EXISTS "${diff.alterView[k].map['old']}"`);

@@ -475,0 +475,0 @@ rtn.alter.push(`CREATE VIEW "${diff.alterView[k].map['new']['name']}" AS ${diff.alterView[k].map['new']['sql']}`);

@@ -10,8 +10,8 @@ "use strict";

const common_1 = require("../libs/common");
const stringType = 'varchar(768)';
const create = ' default current_timestamp';
const update = ' default current_timestamp on update current_timestamp';
const stringType = "varchar(768)";
const create = " default current_timestamp";
const update = " default current_timestamp on update current_timestamp";
const keywords = {
pg: {
fullName: 'pg',
fullName: "pg",
npm: `"pg": "",`,

@@ -21,42 +21,42 @@ quote: { prefix: '"', name: '"', value: "'" },

maxColLen: 64,
idDefaultType: 'cuid',
idDefaultType: "cuid",
idType: {
autoincrement: { jsType: 'number', dbType: 'serial8' },
cuid: { jsType: 'string', dbType: 'cuid' },
uuid: { jsType: 'string', dbType: 'uuid' },
string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'int8' }
autoincrement: { jsType: "number", dbType: "serial8" },
cuid: { jsType: "string", dbType: "cuid" },
uuid: { jsType: "string", dbType: "uuid" },
string: { jsType: "string", dbType: stringType },
int: { jsType: "number", dbType: "int8" },
},
scalarType: {
int: { jsType: 'number', dbType: 'int8' },
object: { jsType: 'object', dbType: 'json' },
float: { jsType: 'number', dbType: 'float8' },
bigint: { jsType: 'bigint', dbType: 'bigint' },
string: { jsType: 'string', dbType: stringType },
boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' }
int: { jsType: "number", dbType: "int8" },
object: { jsType: "object", dbType: "json" },
float: { jsType: "number", dbType: "float8" },
bigint: { jsType: "bigint", dbType: "bigint" },
string: { jsType: "string", dbType: stringType },
boolean: { jsType: "boolean", dbType: "boolean" },
Date: { jsType: "Date", dbType: "timestamp" },
},
dbType: {
enum: 'varchar(30)',
cuid: 'char(25)',
uuid: 'uuid'
enum: "varchar(30)",
cuid: "char(25)",
uuid: "uuid",
},
dbTypes: {
boolean: ['boolean'],
object: ['object'],
float: ['decimal', 'float4', 'float8'],
int: ['int2', 'int4', 'int8', 'money'],
autoincrement: ['serial2', 'serial4', 'serial8'],
Date: ['timestamp', 'date', 'time', 'interval'],
string: []
boolean: ["boolean"],
object: ["object"],
float: ["decimal", "float4", "float8"],
int: ["int2", "int4", "int8", "money"],
autoincrement: ["serial2", "serial4", "serial8"],
Date: ["timestamp", "date", "time", "interval"],
string: [],
},
timestamp: {
create,
update: create
update: create,
},
stmt: {
primaryKey: ' primary key',
autoincrement: '',
unique: ' unique',
index: '',
primaryKey: " primary key",
autoincrement: "",
unique: " unique",
index: "",
constraintPre: (table, action) => `ALTER TABLE ${keywords.pg.quote.prefix}${table}${keywords.pg.quote.name} ${action} `,

@@ -73,7 +73,7 @@ additionalConnectOpts: `pool: {

let Db, db;
if (typeof options === 'string') {
const connStr = path_1.default.join(resolveAcaDir, app, 'node_modules/pg-connection-string');
if (typeof options === "string") {
const connStr = path_1.default.join(resolveAcaDir, app, "node_modules/pg-connection-string");
options = require(connStr).parse(options);
}
Db = require(path_1.default.join(resolveAcaDir, app, 'node_modules/pg')).Client;
Db = require(path_1.default.join(resolveAcaDir, app, "node_modules/pg")).Client;
db = new Db(options);

@@ -86,3 +86,3 @@ try {

...options,
database: 'postgres'
database: "postgres",
});

@@ -92,7 +92,7 @@ await db.connect();

return db;
}
}
},
},
},
mssql: {
fullName: 'mssql',
fullName: "mssql",
npm: `"mssql": "",`,

@@ -102,42 +102,42 @@ quote: { prefix: '"', name: '"', value: "'" },

maxColLen: 128,
idDefaultType: 'cuid',
idDefaultType: "cuid",
idType: {
autoincrement: { jsType: 'number', dbType: 'int' },
cuid: { jsType: 'string', dbType: 'cuid' },
uuid: { jsType: 'string', dbType: 'uuid' },
string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'int' }
autoincrement: { jsType: "number", dbType: "int" },
cuid: { jsType: "string", dbType: "cuid" },
uuid: { jsType: "string", dbType: "uuid" },
string: { jsType: "string", dbType: stringType },
int: { jsType: "number", dbType: "int" },
},
scalarType: {
int: { jsType: 'number', dbType: 'int' },
object: { jsType: 'string', dbType: 'text' },
float: { jsType: 'number', dbType: 'real' },
bigint: { jsType: 'bigint', dbType: 'bigint' },
string: { jsType: 'string', dbType: stringType },
boolean: { jsType: 'number', dbType: 'bit' },
Date: { jsType: 'Date', dbType: 'datetime' }
int: { jsType: "number", dbType: "int" },
object: { jsType: "string", dbType: "text" },
float: { jsType: "number", dbType: "real" },
bigint: { jsType: "bigint", dbType: "bigint" },
string: { jsType: "string", dbType: stringType },
boolean: { jsType: "number", dbType: "bit" },
Date: { jsType: "Date", dbType: "datetime" },
},
dbType: {
enum: 'varchar(30)',
cuid: 'char(25)',
uuid: 'char(36)'
enum: "varchar(30)",
cuid: "char(25)",
uuid: "char(36)",
},
dbTypes: {
boolean: ['boolean'],
object: ['object'],
float: ['decimal', 'float4', 'float8'],
int: ['int2', 'int4', 'int8', 'money'],
autoincrement: ['serial2', 'serial4', 'serial8'],
Date: ['timestamp', 'date', 'time', 'interval'],
string: []
boolean: ["boolean"],
object: ["object"],
float: ["decimal", "float4", "float8"],
int: ["int2", "int4", "int8", "money"],
autoincrement: ["serial2", "serial4", "serial8"],
Date: ["timestamp", "date", "time", "interval"],
string: [],
},
timestamp: {
create,
update: create
update: create,
},
stmt: {
primaryKey: ' primary key',
autoincrement: ' identity',
unique: ' unique',
index: '',
primaryKey: " primary key",
autoincrement: " identity",
unique: " unique",
index: "",
constraintPre: (table, action) => `ALTER TABLE ${keywords.mssql.quote.prefix}${table}${keywords.mssql.quote.name} ${action} `,

@@ -150,8 +150,8 @@ additionalConnectOpts: ``,

let Db, db;
Db = require(path_1.default.join(resolveAcaDir, app, 'node_modules/mssql'));
Db = require(path_1.default.join(resolveAcaDir, app, "node_modules/mssql"));
const opts = {
...options,
options: {
encrypt: false
}
encrypt: false,
},
};

@@ -166,58 +166,58 @@ opts.server = opts.host;

...opts,
database: 'master'
database: "master",
});
}
return db;
}
}
},
},
},
mysql2: {
fullName: 'mysql2',
fullName: "mysql2",
npm: `"mysql2": "",`,
quote: { prefix: '`', name: '`', value: "'" },
quote: { prefix: "`", name: "`", value: "'" },
maxTblLen: 64,
maxColLen: 64,
idDefaultType: 'cuid',
idDefaultType: "cuid",
idType: {
autoincrement: {
jsType: 'number',
dbType: 'int'
jsType: "number",
dbType: "int",
},
cuid: { jsType: 'string', dbType: 'cuid' },
uuid: { jsType: 'string', dbType: 'uuid' },
string: { jsType: 'string', dbType: 'varchar(200)' },
int: { jsType: 'number', dbType: 'int' }
cuid: { jsType: "string", dbType: "cuid" },
uuid: { jsType: "string", dbType: "uuid" },
string: { jsType: "string", dbType: "varchar(200)" },
int: { jsType: "number", dbType: "int" },
},
scalarType: {
int: { jsType: 'number', dbType: 'int' },
object: { jsType: 'object', dbType: 'json' },
float: { jsType: 'number', dbType: 'float8' },
bigint: { jsType: 'bigint', dbType: 'numeric' },
string: { jsType: 'string', dbType: stringType },
boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' }
int: { jsType: "number", dbType: "int" },
object: { jsType: "object", dbType: "json" },
float: { jsType: "number", dbType: "float8" },
bigint: { jsType: "bigint", dbType: "numeric" },
string: { jsType: "string", dbType: stringType },
boolean: { jsType: "boolean", dbType: "boolean" },
Date: { jsType: "Date", dbType: "timestamp" },
},
dbType: {
enum: 'varchar(30)',
cuid: 'char(25)',
uuid: 'char(36)'
enum: "varchar(30)",
cuid: "char(25)",
uuid: "char(36)",
},
dbTypes: {
boolean: ['boolean'],
object: ['object'],
float: ['decimal', 'float4', 'float8'],
int: ['int2', 'int4', 'int8', 'money'],
autoincrement: ['int'],
Date: ['timestamp', 'date', 'time', 'interval'],
string: []
boolean: ["boolean"],
object: ["object"],
float: ["decimal", "float4", "float8"],
int: ["int2", "int4", "int8", "money"],
autoincrement: ["int"],
Date: ["timestamp", "date", "time", "interval"],
string: [],
},
timestamp: {
create: create,
update: create
update: create,
},
stmt: {
primaryKey: ' primary key',
autoincrement: ' auto_increment',
unique: ' unique key',
index: '',
primaryKey: " primary key",
autoincrement: " auto_increment",
unique: " unique key",
index: "",
constraintPre: (table, action) => `ALTER TABLE ${keywords.mysql2.quote.prefix}${table}${keywords.mysql2.quote.name} ${action} `,

@@ -230,3 +230,3 @@ additionalConnectOpts: ``,

let db, pool;
const mysql2 = require(path_1.default.join(resolveAcaDir, app, 'node_modules/mysql2/promise'));
const mysql2 = require(path_1.default.join(resolveAcaDir, app, "node_modules/mysql2/promise"));
try {

@@ -238,58 +238,58 @@ db = await mysql2.createConnection(options);

...options,
database: undefined
database: undefined,
});
}
return db;
}
}
},
},
},
mysql: {
fullName: 'mysql',
fullName: "mysql",
npm: `"mysql": "",`,
quote: { prefix: '`', name: '`', value: "'" },
quote: { prefix: "`", name: "`", value: "'" },
maxTblLen: 64,
maxColLen: 64,
idDefaultType: 'cuid',
idDefaultType: "cuid",
idType: {
autoincrement: {
jsType: 'number',
dbType: 'int'
jsType: "number",
dbType: "int",
},
cuid: { jsType: 'string', dbType: 'cuid' },
uuid: { jsType: 'string', dbType: 'uuid' },
string: { jsType: 'string', dbType: 'varchar(200)' },
int: { jsType: 'number', dbType: 'int' }
cuid: { jsType: "string", dbType: "cuid" },
uuid: { jsType: "string", dbType: "uuid" },
string: { jsType: "string", dbType: "varchar(200)" },
int: { jsType: "number", dbType: "int" },
},
scalarType: {
int: { jsType: 'number', dbType: 'int' },
object: { jsType: 'object', dbType: 'json' },
float: { jsType: 'number', dbType: 'float8' },
bigint: { jsType: 'bigint', dbType: 'numeric' },
string: { jsType: 'string', dbType: stringType },
boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' }
int: { jsType: "number", dbType: "int" },
object: { jsType: "object", dbType: "json" },
float: { jsType: "number", dbType: "float8" },
bigint: { jsType: "bigint", dbType: "numeric" },
string: { jsType: "string", dbType: stringType },
boolean: { jsType: "boolean", dbType: "boolean" },
Date: { jsType: "Date", dbType: "timestamp" },
},
dbType: {
enum: 'varchar(30)',
cuid: 'char(25)',
uuid: 'char(36)'
enum: "varchar(30)",
cuid: "char(25)",
uuid: "char(36)",
},
dbTypes: {
boolean: ['boolean'],
object: ['object'],
float: ['decimal', 'float4', 'float8'],
int: ['int2', 'int4', 'int8', 'money'],
autoincrement: ['int'],
Date: ['timestamp', 'date', 'time', 'interval'],
string: []
boolean: ["boolean"],
object: ["object"],
float: ["decimal", "float4", "float8"],
int: ["int2", "int4", "int8", "money"],
autoincrement: ["int"],
Date: ["timestamp", "date", "time", "interval"],
string: [],
},
timestamp: {
create: create,
update: create
update: create,
},
stmt: {
primaryKey: ' primary key',
autoincrement: ' auto_increment',
unique: ' unique key',
index: '',
primaryKey: " primary key",
autoincrement: " auto_increment",
unique: " unique key",
index: "",
constraintPre: (table, action) => `ALTER TABLE ${keywords.mysql.quote.prefix}${table}${keywords.mysql.quote.name} ${action} `,

@@ -302,3 +302,3 @@ additionalConnectOpts: ``,

let db;
const mysql = require(path_1.default.join(resolveAcaDir, app, 'node_modules/mysql'));
const mysql = require(path_1.default.join(resolveAcaDir, app, "node_modules/mysql"));
db = mysql.createConnection(options);

@@ -312,3 +312,3 @@ try {

...options,
database: undefined
database: undefined,
});

@@ -319,54 +319,54 @@ const conn = (0, util_1.promisify)((cb) => db.connect(cb));

return db;
}
}
},
},
},
betterSqlite3: {
fullName: 'better-sqlite3',
npm: `"better-sqlite3": "",`,
sqlite3: {
fullName: "sqlite3",
npm: `"sqlite3": "",`,
quote: { prefix: '"', name: '"', value: "'" },
maxTblLen: 128,
maxColLen: 128,
idDefaultType: 'cuid',
idDefaultType: "cuid",
idType: {
autoincrement: {
jsType: 'number',
dbType: 'integer'
jsType: "number",
dbType: "integer",
},
cuid: { jsType: 'string', dbType: 'cuid' },
uuid: { jsType: 'string', dbType: 'uuid' },
string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'integer' }
cuid: { jsType: "string", dbType: "cuid" },
uuid: { jsType: "string", dbType: "uuid" },
string: { jsType: "string", dbType: stringType },
int: { jsType: "number", dbType: "integer" },
},
scalarType: {
int: { jsType: 'number', dbType: 'integer' },
object: { jsType: 'object', dbType: 'json' },
float: { jsType: 'number', dbType: 'real' },
bigint: { jsType: 'bigint', dbType: 'integer' },
string: { jsType: 'string', dbType: stringType },
boolean: { jsType: 'boolean', dbType: 'integer' },
Date: { jsType: 'Date', dbType: 'timestamp' }
int: { jsType: "number", dbType: "integer" },
object: { jsType: "object", dbType: "json" },
float: { jsType: "number", dbType: "real" },
bigint: { jsType: "bigint", dbType: "integer" },
string: { jsType: "string", dbType: stringType },
boolean: { jsType: "boolean", dbType: "integer" },
Date: { jsType: "Date", dbType: "timestamp" },
},
dbType: {
enum: 'varchar(30)',
cuid: 'char(25)',
uuid: 'char(36)'
enum: "varchar(30)",
cuid: "char(25)",
uuid: "char(36)",
},
dbTypes: {
boolean: ['integer'],
object: ['text'],
float: ['float', 'double', 'real'],
int: ['integer', 'smallint'],
autoincrement: ['integer'],
Date: ['timestamp', 'date', 'time'],
string: []
boolean: ["integer"],
object: ["text"],
float: ["float", "double", "real"],
int: ["integer", "smallint"],
autoincrement: ["integer"],
Date: ["timestamp", "date", "time"],
string: [],
},
timestamp: {
create,
update: create
update: create,
},
stmt: {
primaryKey: ' primary key',
autoincrement: ' autoincrement',
unique: ' unique',
index: '',
primaryKey: " primary key",
autoincrement: " autoincrement",
unique: " unique",
index: "",
constraintPre: (table, action) => ``,

@@ -379,3 +379,3 @@ additionalConnectOpts: `useNullAsDefault: false,`,

let Db, db;
db = require(path_1.default.join(resolveAcaDir, app, 'node_modules/better-sqlite3'));
db = require(path_1.default.join(resolveAcaDir, app, "node_modules/sqlite3")).verbose().Database;
const dbName = path_1.default.join(resolveAcaDir, app, options.filename);

@@ -385,8 +385,8 @@ return fs_1.default.existsSync(dbName)

...options,
filename: undefined
filename: undefined,
})
: null;
}
}
}
},
},
},
};

@@ -405,3 +405,3 @@ function default_1(driver) {

return {
pg: ` SELECT * FROM pg_database WHERE datname = ${qPrefix}${dbName}${qName}`
pg: ` SELECT * FROM pg_database WHERE datname = ${qPrefix}${dbName}${qName}`,
}[driver];

@@ -414,10 +414,10 @@ },

AND tablename NOT LIKE 'sql_%'
ORDER BY tablename`
ORDER BY tablename`,
}[driver];
},
create(dbName) {
return `CREATE DATABASE ${qPrefix}${dbName}${qName}${driver === 'pg' ? ' template=template0' : ''}`;
return `CREATE DATABASE ${qPrefix}${dbName}${qName}${driver === "pg" ? " template=template0" : ""}`;
},
drop(dbName) {
return `DROP DATABASE ${qPrefix}${dbName}${qName}${driver === 'pg' ? 'template=template0' : ''}`;
return `DROP DATABASE ${qPrefix}${dbName}${qName}${driver === "pg" ? "template=template0" : ""}`;
},

@@ -434,9 +434,9 @@ rename(dbName) {

}
const db = require(path_1.default.join(resolveAcaDir, apps[0], 'node_modules/better-sqlite3'));
const db = require(path_1.default.join(resolveAcaDir, apps[0], "node_modules/sqlite3")).verbose();
const filename = path_1.default.join(resolveAcaDir, apps[0], option.filename);
return new db(filename, {
return new db.Database(filename, {
...option,
filename: undefined
});
}
},
},

@@ -449,3 +449,3 @@ tbl(table) {

pg: `select * from information_schema.columns
where table_schema = 'public' and table_name='${table}'`
where table_schema = 'public' and table_name='${table}'`,
}[driver];

@@ -467,5 +467,10 @@ },

const cols = columns
.map((v) => `ADD COLUMN ${qName}${v.name}${qName} ${v.dbType.toUpperCase()}${v.notNull ? ' NOT NULL' : ''}${v.default !== undefined ? ` DEFAULT ${typeof v.default === 'string' ? v.default ? v.default : '' : v.default}` : ''}`)
.join(', ');
return `ALTER TABLE ${qPrefix}${table}${qName} ${cols}`;
.map((v) => `ADD COLUMN ${qName}${v.name}${qName} ${v.dbType.toUpperCase()}${v.notNull ? " NOT NULL" : ""}${v.default !== undefined
? ` DEFAULT ${typeof v.default === "string"
? v.default
? `'${v.default}'`
: `'${v.default}'`
: v.default}`
: ""}`);
return cols.map(v => `ALTER TABLE ${qPrefix}${table}${qName} ${v}`).join(';\n');
},

@@ -475,5 +480,3 @@ drop(columns) {

columns = [columns];
return `ALTER TABLE ${qPrefix}${table}${qName} ${columns
.map((v) => `DROP COLUMN ${qName}${v}${qName}`)
.join(', ')}`;
return columns.map(v => `ALTER TABLE ${qPrefix}${table}${qName} DROP COLUMN ${qName}${v}${qName}`).join(';\n');
},

@@ -486,10 +489,10 @@ alter(column) {

type(dbName) {
if (['cuid', 'uuid', 'enum'].includes(dbName)) {
if (["cuid", "uuid", "enum"].includes(dbName)) {
dbName = keyword.dbType[dbName];
}
if (driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改');
if (driver === "sqlite3") {
throw new Error("sqlite3 暂不支持修改");
}
let sql = `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} TYPE ${dbName}`;
if (driver === 'pg') {
if (driver === "pg") {
sql += ` USING ${qName}${column}${qName}::${dbName}`;

@@ -500,4 +503,4 @@ }

notNull(action) {
if (driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改');
if (driver === "sqlite3") {
throw new Error("sqlite3 暂不支持修改");
}

@@ -507,15 +510,17 @@ return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${action} NOT NULL`;

check(value) {
if (driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改');
if (driver === "sqlite3") {
throw new Error("sqlite3 暂不支持修改");
}
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined ? `SET CHECK ${qValue}${value}${qValue}` : 'DROP CHECK'}`;
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined
? `SET CHECK ${qValue}${value}${qValue}`
: "DROP CHECK"}`;
},
default(value) {
if (driver === 'betterSqlite3') {
throw new Error('betterSqlite3 暂不支持修改');
if (driver === "sqlite3") {
throw new Error("sqlite3 暂不支持修改");
}
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined ? `SET DEFAULT ${value}` : 'DROP DEFAULT'}`;
}
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined ? `SET DEFAULT ${value}` : "DROP DEFAULT"}`;
},
};
}
},
},

@@ -534,8 +539,8 @@ constraint: {

JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = '${type}' AND tc.table_name = '${table}'`
WHERE constraint_type = '${type}' AND tc.table_name = '${table}'`,
}[driver];
},
foreign(action, foreign, relTbl) {
if (action === 'ADD' && relTbl) {
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}FOREIGN_${table}_${foreign.keys.join('_')}${qName} FOREIGN KEY (${foreign.keys
if (action === "ADD" && relTbl) {
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}FOREIGN_${table}_${foreign.keys.join("_")}${qName} FOREIGN KEY (${foreign.keys
.map((v) => `${qName}${v}${qName}`)

@@ -545,30 +550,35 @@ .toString()}) REFERENCES ${qName}${relTbl.dbName}${qName} (${foreign.references

.map((v) => `${qName}${v}${qName}`)
.toString()})${foreign.onUpdate ? ` on update ${foreign.onUpdate}` : ''}${foreign?.onDelete ? ` on delete ${foreign.onDelete}` : ''}`;
.toString()})${foreign.onUpdate ? ` on update ${foreign.onUpdate}` : ""}${foreign?.onDelete ? ` on delete ${foreign.onDelete}` : ""}`;
}
else {
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}FOREIGN_${table}_${foreign.keys.join('_')}${qName}`;
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}FOREIGN_${table}_${foreign.keys.join("_")}${qName}`;
}
},
unique(action, columns) {
if (typeof columns === 'string')
if (typeof columns === "string")
columns = [columns];
const key = columns.join('_');
const quoteCols = `${columns.map((v) => `${qName}${v}${qName}`).toString()}`;
if ('betterSqlite3' === driver) {
if (action === 'DROP') {
const key = columns.join("_");
const quoteCols = `${columns
.map((v) => `${qName}${v}${qName}`)
.toString()}`;
if ("sqlite3" === driver) {
if (action === "DROP") {
return `DROP INDEX ${qName}UNIQUE_${table}_${key}${qName}`;
}
else if (action === 'ADD') {
else if (action === "ADD") {
return `CREATE UNIQUE INDEX ${qName}UNIQUE_${table}_${key}${qName} ON ${qName}${table}${qName}(${quoteCols})`;
}
}
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}UNIQUE_${table}_${key}${qName}${action === 'ADD' ? ` UNIQUE (${quoteCols})` : ''}`;
return `${keyword.stmt.constraintPre(table, action)}CONSTRAINT ${qName}UNIQUE_${table}_${key}${qName}${action === "ADD" ? ` UNIQUE (${quoteCols})` : ""}`;
},
index(action, columns) {
const key = typeof columns === 'string' ? columns : columns.join('_');
const key = typeof columns === "string" ? columns : columns.join("_");
let quoteCols = `${qName}${columns}${qName}`;
quoteCols = typeof columns === 'string' ? quoteCols : quoteCols.toString();
return `${action} INDEX ${qName}INDEX_${table}_${key}${qName}${action === 'CREATE' ? ` ON ${qName}${table}${qName} (${quoteCols})` : ''}`;
}
}
quoteCols =
typeof columns === "string" ? quoteCols : quoteCols.toString();
return `${action} INDEX ${qName}INDEX_${table}_${key}${qName}${action === "CREATE"
? ` ON ${qName}${table}${qName} (${quoteCols})`
: ""}`;
},
},
};

@@ -589,5 +599,5 @@ },

async rename(column) { },
async alter(column) { }
async alter(column) { },
};
}
},
};

@@ -597,7 +607,7 @@ },

create: `\nCREATE TABLE ${qPrefix}___ACA${qName} (${qName}version${qName} varchar(18) PRIMARY KEY, ${qName}preverison${qName} varchar(18), ${qName}orm${qName} text);\n`,
insert: (version, orm) => `\nINSERT INTO ${qPrefix}___ACA${qName} (${qName}version${qName}, ${qName}orm${qName}) VALUES (${qValue}${version}${qValue}, ${qValue}${orm || ''}${qValue});\n`,
select: `\nSELECT * FROM ${qPrefix}___ACA${qName};\n`
}
insert: (version, orm) => `\nINSERT INTO ${qPrefix}___ACA${qName} (${qName}version${qName}, ${qName}orm${qName}) VALUES (${qValue}${version}${qValue}, ${qValue}${orm || ""}${qValue});\n`,
select: `\nSELECT * FROM ${qPrefix}___ACA${qName};\n`,
},
};
}
exports.default = default_1;

@@ -36,17 +36,17 @@ "use strict";

const ts = __importStar(require("typescript"));
BigInt.prototype['toJSON'] = function () {
BigInt.prototype["toJSON"] = function () {
return this.toString();
};
const KindCode = {
[ts.SyntaxKind.ImportDeclaration]: 'import',
[ts.SyntaxKind.VariableStatement]: 'const',
[ts.SyntaxKind.BooleanKeyword]: 'boolean',
[ts.SyntaxKind.NumberKeyword]: 'number',
[ts.SyntaxKind.StringKeyword]: 'string',
[ts.SyntaxKind.EnumDeclaration]: 'enum',
[ts.SyntaxKind.ClassDeclaration]: 'table',
[ts.SyntaxKind.ModuleDeclaration]: 'namespace',
[ts.SyntaxKind.ImportDeclaration]: "import",
[ts.SyntaxKind.VariableStatement]: "const",
[ts.SyntaxKind.BooleanKeyword]: "boolean",
[ts.SyntaxKind.NumberKeyword]: "number",
[ts.SyntaxKind.StringKeyword]: "string",
[ts.SyntaxKind.EnumDeclaration]: "enum",
[ts.SyntaxKind.ClassDeclaration]: "table",
[ts.SyntaxKind.ModuleDeclaration]: "namespace",
};
const QualifiedName = (n) => {
let rtn = '';
let rtn = "";
if (n.kind === ts.SyntaxKind.Identifier)

@@ -61,3 +61,3 @@ return n.text;

}
return rtn + '.' + n.right.text;
return rtn + "." + n.right.text;
};

@@ -68,6 +68,6 @@ const NodeParse = {

return (NodeParse.type(typ.elementType) +
(typ.elementType['typeName']?.text === 'id'
? ''
: '[]'));
let rtn = '';
(typ.elementType["typeName"]?.text === "id"
? ""
: "[]"));
let rtn = "";
switch (typ.kind) {

@@ -81,8 +81,8 @@ case ts.SyntaxKind.BooleanKeyword:

rtn = {
[ts.SyntaxKind.BooleanKeyword]: 'boolean',
[ts.SyntaxKind.StringKeyword]: 'string',
[ts.SyntaxKind.NumberKeyword]: 'number',
[ts.SyntaxKind.BigIntKeyword]: 'bigint',
[ts.SyntaxKind.ObjectKeyword]: 'object',
[ts.SyntaxKind.AnyKeyword]: 'any',
[ts.SyntaxKind.BooleanKeyword]: "boolean",
[ts.SyntaxKind.StringKeyword]: "string",
[ts.SyntaxKind.NumberKeyword]: "number",
[ts.SyntaxKind.BigIntKeyword]: "bigint",
[ts.SyntaxKind.ObjectKeyword]: "object",
[ts.SyntaxKind.AnyKeyword]: "any",
}[typ.kind];

@@ -112,3 +112,3 @@ break;

rtn = {
type: 'boolean',
type: "boolean",
initializer: {

@@ -123,3 +123,3 @@ [ts.SyntaxKind.TrueKeyword]: true,

rtn = {
type: text.indexOf('.') === -1 ? 'int' : 'float',
type: text.indexOf(".") === -1 ? "int" : "float",
initializer: text,

@@ -130,4 +130,4 @@ };

rtn = {
type: 'bigint',
initializer: `${exp.text.replace(/n$/, '')}`,
type: "bigint",
initializer: `${exp.text.replace(/n$/, "")}`,
};

@@ -137,3 +137,3 @@ break;

rtn = {
type: 'string',
type: "string",
initializer: `${exp.text}`,

@@ -151,3 +151,3 @@ };

rtn = {
type: 'object',
type: "object",
initializer: exp.properties.reduce((_3, v3) => {

@@ -161,3 +161,3 @@ _3[v3.name.text] = NodeParse.initializer(v3.initializer);

rtn = {
type: 'Identifier',
type: "Identifier",
initializer: `'${exp.text}'`,

@@ -170,4 +170,4 @@ };

type: {
[ts.SyntaxKind.CallExpression]: 'callExpression',
[ts.SyntaxKind.NewExpression]: 'newExpression',
[ts.SyntaxKind.CallExpression]: "callExpression",
[ts.SyntaxKind.NewExpression]: "newExpression",
}[exp.kind],

@@ -178,12 +178,12 @@ expression: exp.expression.text,

switch (rtn.expression) {
case 'BigInt':
case "BigInt":
rtn = {
type: 'bigint',
initializer: rtn.initializer[0].initializer.replace(/n/, ''),
type: "bigint",
initializer: rtn.initializer[0].initializer.replace(/n/, ""),
};
break;
case 'Date':
case "Date":
rtn = {
type: 'datetime',
initializer: 'CURRENT_TIMESTAMP',
type: "datetime",
initializer: "CURRENT_TIMESTAMP",
};

@@ -195,3 +195,3 @@ break;

rtn = {
type: 'NoSubstitutionTemplateLiteral',
type: "NoSubstitutionTemplateLiteral",
initializer: exp.text,

@@ -202,3 +202,3 @@ };

console.log(`Default values not processed: ${JSON.stringify(exp, null, 2)}`);
rtn = { type: '', initializer: '' };
rtn = { type: "", initializer: "" };
}

@@ -212,3 +212,3 @@ return rtn;

const exp = v.expression;
let key = '', value;
let key = "", value;
switch (exp.kind) {

@@ -227,3 +227,3 @@ case ts.SyntaxKind.Identifier:

QualifiedName(callExp.expression) +
'.' +
"." +
callExp.name.text;

@@ -247,4 +247,4 @@ value = exp.arguments.map((v2) => {

}
if (['$.unique', '$.index'].includes(key)) {
const k = { '$.unique': 'uniques', '$.index': 'indexes' }[key];
if (["$.unique", "$.index"].includes(key)) {
const k = { "$.unique": "uniques", "$.index": "indexes" }[key];
_[k] = _[k] || [];

@@ -254,3 +254,3 @@ _[k].push(value);

else {
_[key.split('.').reverse()[0]] = value;
_[key.split(".").reverse()[0]] = value;
}

@@ -270,3 +270,3 @@ return _;

const Iter = (subAst, namespace = []) => {
let qualified = config.databases['default'].tableNameWithNamespace
let qualified = config.databases["default"].tableNameWithNamespace
? namespace

@@ -282,6 +282,6 @@ : [];

if (importV.moduleSpecifier.text ===
'./schema-property')
"./schema-property")
break;
if (clause?.name) {
named[clause.name.text] = 'default';
named[clause.name.text] = "default";
}

@@ -291,3 +291,3 @@ if (clause?.namedBindings) {

case ts.SyntaxKind.NamespaceImport:
named[clause.namedBindings.name.text] = '*';
named[clause.namedBindings.name.text] = "*";
break;

@@ -310,14 +310,14 @@ case ts.SyntaxKind.NamedImports:

name: v2.name.text,
type: '',
initializer: '',
type: "",
initializer: "",
};
if (v2.initializer) {
const init = NodeParse.initializer(v2.initializer);
if ('$db' === v2.type?.typeName.text) {
namesRtn.name = '$';
if ("$db" === v2.type?.typeName.text) {
namesRtn.name = "$";
namesRtn.initializer = init.initializer;
}
namesRtn.type = v2.type ? KindCode[v2.type.kind] : init.type;
if (['int', 'float'].includes(namesRtn.type))
namesRtn.type = 'number';
if (["int", "float"].includes(namesRtn.type))
namesRtn.type = "number";
namesRtn.initializer = init.initializer;

@@ -328,7 +328,7 @@ }

}, []);
if (1 === names.length && '$' === names[0].name) {
_['$'] = { kind: 'dbConfig', $: names[0].initializer };
if (1 === names.length && "$" === names[0].name) {
_["$"] = { kind: "dbConfig", $: names[0].initializer };
}
else
schm.vars.push({ kind: 'const', names });
schm.vars.push({ kind: "const", names });
break;

@@ -339,3 +339,3 @@ case ts.SyntaxKind.ModuleDeclaration:

_[name] = {
kind: 'namespace',
kind: "namespace",
name,

@@ -350,3 +350,3 @@ namespace: namespace.slice(1) || [],

_[name] = {
kind: 'enum',
kind: "enum",
name,

@@ -361,6 +361,8 @@ namespace,

name = classV.name.text;
let props = NodeParse.decorator((ts.canHaveDecorators ? ts.getDecorators(classV) : (classV.decorators || [])));
let props = NodeParse.decorator(ts.canHaveDecorators
? ts.getDecorators(classV)
: classV.decorators || []);
let MR = (0, common_1.MapRename)(props);
const body = {
kind: 'table',
kind: "table",
name,

@@ -371,31 +373,31 @@ map: MR.map,

if (classV.heritageClauses) {
body['extends'] = classV.heritageClauses.map((v) => v.types[0].expression.escapedText);
body["extends"] = classV.heritageClauses.map((v) => v.types[0].expression.escapedText);
}
body['jsName'] = [...qualified, name].join(constant_1.Delimiter);
body['dbName'] = [...(qualified.slice(1) || []), MR.map || name].join(constant_1.Delimiter);
if (props['view']) {
body.kind = 'view';
body['sql'] = props['view'];
body['uniques'] = [];
body['indexes'] = [];
if (props['id'])
(body['id'] = props['id']), body['uniques'].push(props['id']);
if (props['uniques'])
body['uniques'].push(...props['uniques']);
delete props['view'];
body["jsName"] = [...qualified, name].join(constant_1.Delimiter);
body["dbName"] = [...(qualified.slice(1) || []), MR.map || name].join(constant_1.Delimiter);
if (props["view"]) {
body.kind = "view";
body["sql"] = props["view"];
body["uniques"] = [];
body["indexes"] = [];
if (props["id"])
(body["id"] = props["id"]), body["uniques"].push(props["id"]);
if (props["uniques"])
body["uniques"].push(...props["uniques"]);
delete props["view"];
}
else {
body['uniques'] = [];
body['indexes'] = [];
if (props['id'])
(body['id'] = props['id']), body['uniques'].push(props['id']);
if (props['uniques'])
body['uniques'].push(...props['uniques']);
if (props['indexes'])
body['indexes'].push(...props['indexes']);
body["uniques"] = [];
body["indexes"] = [];
if (props["id"])
(body["id"] = props["id"]), body["uniques"].push(props["id"]);
if (props["uniques"])
body["uniques"].push(...props["uniques"]);
if (props["indexes"])
body["indexes"].push(...props["indexes"]);
}
body['props'] = props;
body['columns'] = classV.members.reduce((_2, v2) => {
body["props"] = props;
body["columns"] = classV.members.reduce((_2, v2) => {
const V2 = v2;
props = NodeParse.decorator((ts.canHaveDecorators ? ts.getDecorators(V2) : (V2.decorators || [])));
props = NodeParse.decorator(ts.canHaveDecorators ? ts.getDecorators(V2) : V2.decorators || []);
MR = (0, common_1.MapRename)(props);

@@ -406,17 +408,17 @@ let colKey = V2.name.text;

map: MR.map,
optional: V2.questionToken ? 'optional' : 'required',
optional: V2.questionToken ? "optional" : "required",
};
col['jsName'] = colKey;
col['dbName'] = MR.map || colKey;
if (body.kind === 'table') {
col['props'] = props;
if (props['unique'])
body['uniques'].push([colKey]);
if (props['index'])
body['indexes'].push([colKey]);
col["jsName"] = colKey;
col["dbName"] = MR.map || colKey;
if (body.kind === "table") {
col["props"] = props;
if (props["unique"])
body["uniques"].push([colKey]);
if (props["index"])
body["indexes"].push([colKey]);
}
if (body.kind === 'view') {
col['props'] = props;
if (props['unique'])
body['uniques'].push([colKey]);
if (body.kind === "view") {
col["props"] = props;
if (props["unique"])
body["uniques"].push([colKey]);
}

@@ -426,10 +428,10 @@ let init;

init = NodeParse.initializer(V2.initializer);
col['props']['default'] = init.initializer;
col.optional = 'optional';
col["props"]["default"] = init.initializer;
col.optional = "optional";
}
if (V2.type) {
col['type'] = NodeParse.type(V2.type);
const idType = col['type'].match(/^id(\[\w+\])?$/);
if (idType && col['props']) {
col['props'].isId = true;
col["type"] = NodeParse.type(V2.type);
const idType = col["type"].match(/^id(\[\w+\])?$/);
if (idType && col["props"]) {
col["props"].isId = true;
}

@@ -440,3 +442,3 @@ }

throw `field '${colKey}', data type is not defined`;
col['type'] = init.type;
col["type"] = init.type;
}

@@ -456,5 +458,5 @@ _2[colKey] = col;

const DbConfig = (db) => {
if (!db.models['$']) {
if (!db.models["$"]) {
if (config.databases) {
db.models['$'] = config.databases['default'];
db.models["$"] = config.databases["default"];
}

@@ -465,8 +467,8 @@ else

else {
const confName = db.models['$']['$'];
if (typeof confName === 'string') {
db.models['$'] = config?.databases[confName] || confName;
const confName = db.models["$"]["$"];
if (typeof confName === "string") {
db.models["$"] = config?.databases[confName] || confName;
}
else if (typeof confName === 'object') {
db.models['$'] = confName;
else if (typeof confName === "object") {
db.models["$"] = confName;
}

@@ -482,7 +484,7 @@ else

throw `Type definition: ${relName} not found`;
const qual = relName.split('.');
const qual = relName.split(".");
const nsModels = (ns) => ns.reduce((_, k) => (_ = _[k].models), db);
const mdl = (mdls, name) => {
Object.keys(mdls).some((k) => {
if ('namespace' !== mdls[k].kind) {
if ("namespace" !== mdls[k].kind) {
const key = mdls[k].name;

@@ -522,3 +524,3 @@ if (key === name)

};
const driver = db['$'].connectOption.driver;
const driver = db["$"].connectOption.driver;
const sqlDiff = (0, sql_diff_1.default)(driver);

@@ -528,7 +530,7 @@ const IterFill = (subModels) => {

switch (subModels[k].kind) {
case 'namespace':
case "namespace":
IterFill(subModels[k].models);
break;
case 'view':
case 'table':
case "view":
case "table":
const tbl = subModels[k];

@@ -543,3 +545,3 @@ if (tbl.extends) {

switch (typ[1]) {
case 'id':
case "id":
tbl.id = [col.jsName];

@@ -549,13 +551,13 @@ tbl.uniques.push([col.jsName]);

(sqlDiff.keyword.dbTypes.autoincrement.includes(col.props.dbType)
? 'autoincrement'
? "autoincrement"
: sqlDiff.keyword.dbTypes.int.includes(col.props.dbType)
? 'int'
: col.props.dbType?.toLocaleLowerCase().includes('char')
? 'string'
: db['$'].idDefaultType) ||
? "int"
: col.props.dbType?.toLocaleLowerCase().includes("char")
? "string"
: db["$"].idDefaultType) ||
sqlDiff.keyword.idDefaultType;
col.type = 'id';
col.optional = ['cuid', 'uuid', 'autoincrement'].includes(idType)
? 'optional'
: 'required';
col.type = "id";
col.optional = ["cuid", "uuid", "autoincrement"].includes(idType)
? "optional"
: "required";
col.props.idType = idType;

@@ -566,11 +568,11 @@ col.props.jsType = sqlDiff.keyword.idType[idType].jsType;

break;
case 'Date':
case "Date":
if (col.props.createdAt || col.props.updatedAt)
col.optional = 'optional';
case 'boolean':
case 'int':
case 'float':
case 'bigint':
case 'string':
case 'object':
col.optional = "optional";
case "boolean":
case "int":
case "float":
case "bigint":
case "string":
case "object":
col.props.jsType = col.type.replace(typ[1], sqlDiff.keyword.scalarType[typ[1]].jsType);

@@ -581,3 +583,3 @@ col.props.dbType =

break;
case 'enum':
case "enum":
break;

@@ -587,12 +589,12 @@ default:

switch (relModel.kind) {
case 'enum':
col.type = 'enum';
col.props.dbType = 'varchar(20)';
case "enum":
col.type = "enum";
col.props.dbType = "varchar(20)";
col.props.jsType = relModel.jsName;
break;
case 'table':
const lastDot = typ[1].lastIndexOf('.');
case "table":
const lastDot = typ[1].lastIndexOf(".");
const relTbl = typ[1].slice(lastDot + 1);
const qualNs = [...relModel.namespace];
col.type = [...qualNs, relTbl].join('.') + (typ[3] || '');
col.type = [...qualNs, relTbl].join(".") + (typ[3] || "");
col.props.jsType = `${[dbVar, ...qualNs].join(constant_1.Delimiter)}`;

@@ -608,9 +610,9 @@ }

switch (subModels[k].kind) {
case 'namespace':
case "namespace":
IterRelate(subModels[k].models);
break;
case 'table':
case "table":
const typeReg = /([^\[]+)(?:\[(\w+)\])?(\?|\[\])?$/;
const tbl = subModels[k];
const tblName = [...tbl.namespace, tbl.name].join('.');
const tblName = [...tbl.namespace, tbl.name].join(".");
for (const k2 in tbl.columns) {

@@ -626,32 +628,32 @@ const col = tbl.columns[k2];

col.type =
[...relTbl.namespace, relTbl.name, relCol.name].join('.') +
(typ[3] || (relCol.optional === 'optional' ? '?' : ''));
[...relTbl.namespace, relTbl.name, relCol.name].join(".") +
(typ[3] || (relCol.optional === "optional" ? "?" : ""));
relCol.type =
[...tbl.namespace, tbl.name, col.name].join('.') +
(relTyp[3] || (col.optional === 'optional' ? '?' : ''));
[...tbl.namespace, tbl.name, col.name].join(".") +
(relTyp[3] || (col.optional === "optional" ? "?" : ""));
col.props.jsType +=
constant_1.Delimiter +
relTbl.name +
'.' +
"." +
relCol.name +
(typ[3] || (relCol.optional === 'optional' ? '?' : ''));
(typ[3] || (relCol.optional === "optional" ? "?" : ""));
relCol.props.jsType +=
constant_1.Delimiter +
tbl.name +
'.' +
"." +
col.name +
(relTyp[3] || (col.optional === 'optional' ? '?' : ''));
(relTyp[3] || (col.optional === "optional" ? "?" : ""));
col.props.dbType =
[...relTbl.namespace, relTbl.map || relTbl.name].join(constant_1.Delimiter) +
'.' +
"." +
(relCol.map || relCol.name) +
(typ[3] || (relCol.optional === 'optional' ? '?' : ''));
(typ[3] || (relCol.optional === "optional" ? "?" : ""));
relCol.props.dbType =
[...tbl.namespace, tbl.map || tbl.name].join(constant_1.Delimiter) +
'.' +
"." +
(col.map || col.name) +
(relTyp[3] || (col.optional === 'optional' ? '?' : ''));
(relTyp[3] || (col.optional === "optional" ? "?" : ""));
const addForeign = (PT, PF, FT, FF) => {
let FR = FF.props.foreign;
if (typeof FR === 'string' || Array.isArray(FR)) {
if (typeof FR === "string" || Array.isArray(FR)) {
const tmpFR = {

@@ -661,3 +663,3 @@ keys: [],

};
tmpFR.keys = typeof FR === 'string' ? [FR] : FR;
tmpFR.keys = typeof FR === "string" ? [FR] : FR;
if (PT.id.length === tmpFR.keys.length)

@@ -669,7 +671,7 @@ tmpFR.references = PT.id;

}
if (PF.type.endsWith(']')) {
PF.type = PF.type.replace('[]', '');
PF.props.jsType = PF.props.jsType.replace('[]', '');
PF.props.dbType = PF.props.dbType.replace('[]', '');
PF.optional = 'array';
if (PF.type.endsWith("]")) {
PF.type = PF.type.replace("[]", "");
PF.props.jsType = PF.props.jsType.replace("[]", "");
PF.props.dbType = PF.props.dbType.replace("[]", "");
PF.optional = "array";
}

@@ -687,3 +689,3 @@ for (let keys = FR.keys, refs = FR.references, i = 0; i < keys.length; i++) {

name: keys[i],
map: '',
map: "",
optional: FF.optional,

@@ -697,4 +699,4 @@ jsName: keys[i],

...FR,
jsType: FF.props.jsType
}
jsType: FF.props.jsType,
},
},

@@ -704,7 +706,7 @@ type: relF.type,

if (!FT.columns[keys[i]].props.isId &&
['SERIAL2', 'SERIAL4', 'SERIAL8'].includes(relF.props.dbType)) {
["SERIAL2", "SERIAL4", "SERIAL8"].includes(relF.props.dbType)) {
FT.columns[keys[i]].props.dbType = {
SERIAL2: 'INT2',
SERIAL4: 'INT4',
SERIAL8: 'INT8',
SERIAL2: "INT2",
SERIAL4: "INT4",
SERIAL8: "INT8",
}[relF.props.dbType];

@@ -740,3 +742,3 @@ }

for (const k in dbs) {
if (dbs[k].kind === 'namespace') {
if (dbs[k].kind === "namespace") {
DbConfig(dbs[k]);

@@ -748,6 +750,6 @@ Perfect(dbs[k].models, k);

const IterDbs = (models) => Object.keys(models).reduce((_, k) => {
if ('namespace' === models[k].kind) {
if ("namespace" === models[k].kind) {
_[k] = IterDbs(models[k].models);
}
else if ('enum' === models[k].kind) {
else if ("enum" === models[k].kind) {
rtn.enums[models[k].jsName] = models[k];

@@ -763,7 +765,7 @@ delete models[k];

for (const k in dbsTmp) {
if (dbsTmp[k].kind === 'table')
if (dbsTmp[k].kind === "table")
continue;
rtn.dbs[k] = { config: {}, tables: {} };
for (const k2 in dbsTmp[k]) {
if ('$' === k2)
if ("$" === k2)
rtn.dbs[k].config = dbsTmp[k][k2];

@@ -780,5 +782,5 @@ else

const config = require(path_1.default.join(acaRoot, Cst.AcaConfig));
content = fs_1.default.readFileSync(path_1.default.join(acaRoot, Cst.AcaDir, config.orm), 'utf-8');
content = fs_1.default.readFileSync(path_1.default.join(acaRoot, Cst.AcaDir, config.orm), "utf-8");
}
const ast = ts.createSourceFile('', content, ts.ScriptTarget.ES2020, false);
const ast = ts.createSourceFile("", content, ts.ScriptTarget.ES2020, false);
const pickModel = await PickModel(acaDir, ast);

@@ -785,0 +787,0 @@ return pickModel;

{
"name": "aca.ts",
"version": "0.0.92",
"description": "ACA.ts is a fullstack development toolkit, which can automatically synchronize database schema and generate database query APIs according to a typescript ORM document; Automatically generate the client access server APIs according to the server functions and database query APIs, so that the client code can be developed on the client.",
"version": "0.0.93",
"description": "Aca.ts is a full stack development tool without backend development, which can automatically synchronize database schema and generate database query APIs according to a typescript ORM document; Automatically generate the client access server APIs according to the server functions and database query APIs, so that the client code can be developed on the client.",
"keywords": [

@@ -37,3 +37,3 @@ "aca",

"shelljs": "",
"typescript": "^4.8.4",
"typescript": "",
"util": "",

@@ -40,0 +40,0 @@ "yargs": ""

@@ -13,3 +13,3 @@ {

"connectOption": {
"driver": "betterSqlite3",
"driver": "sqlite3",
"envConnect": "",

@@ -16,0 +16,0 @@ "connect": {

@@ -67,3 +67,3 @@ {

"mariadb",
"betterSqlite3"
"sqlite3"
]

@@ -70,0 +70,0 @@ },

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