Browse Source

feat: relations(wip)

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/341/head
Pranav C 3 years ago
parent
commit
744644498c
  1. 1
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  2. 12832
      packages/nocodb/package-lock.json
  3. 3
      packages/nocodb/package.json
  4. 265
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  5. 2
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts
  6. 2
      packages/nocodb/src/lib/utils/NcHelp.ts

1
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -28,6 +28,7 @@
<virtual-header-cell v-if="col.virtual"
:column="col"
:nodes="nodes"
@saved="onNewColCreation"
/>

12832
packages/nocodb/package-lock.json generated

File diff suppressed because it is too large Load Diff

3
packages/nocodb/package.json

@ -125,6 +125,7 @@
"handlebars": "^4.7.6",
"import-fresh": "^3.2.1",
"inflection": "^1.12.0",
"is-docker": "^2.2.1",
"js-beautify": "^1.11.0",
"json2csv": "^5.0.6",
"jsonfile": "^6.1.0",
@ -142,7 +143,7 @@
"mysql2": "^2.2.5",
"nanoid": "^3.1.20",
"nc-common": "0.0.6",
"nc-help": "^0.1.113",
"nc-help": "file:../../../xc-lib-private",
"nc-lib-gui": "^0.1.239",
"nc-plugin": "^0.1.1",
"nodemailer": "^6.4.10",

265
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -2455,7 +2455,6 @@ export default class NcMetaMgr {
}
// todo : transaction
protected async xcRelationColumnDelete(args: any, req): Promise<any> {
const dbAlias = this.getDbAlias(args);
@ -2500,7 +2499,12 @@ export default class NcMetaMgr {
}
{
const originalColumns = childMeta.columns;
const columns = childMeta.columns.map(c => ({...c, ...(relation.cn === c.cn ? {altered: 4} : {})}))
const columns = childMeta.columns.map(c => ({
...c, ...(relation.cn === c.cn ? {
altered: 4,
cno: c.cn
} : {cno: c.cn})
}))
const opArgs = {
...args,
@ -2508,11 +2512,257 @@ export default class NcMetaMgr {
columns,
originalColumns,
tn: childMeta.tn,
sqlOpPlus: true
},
sqlOpPlus: true,
api: 'tableUpdate'
}
/*
*
* {
"tn": "sdhsdjhs",
"originalColumns": [
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "id",
"_cn": "Id",
"type": "integer",
"dt": "int",
"uidt": "ID",
"uip": "",
"uicn": "",
"dtx": "integer",
"ct": "int(11)",
"nrqd": false,
"rqd": true,
"ck": false,
"pk": true,
"un": true,
"ai": true,
"cdf": null,
"clen": null,
"np": 11,
"ns": 0,
"dtxp": "11",
"dtxs": ""
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "title",
"_cn": "Title",
"type": "string",
"dt": "varchar",
"uidt": "SingleLineText",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": null,
"clen": 45,
"np": null,
"ns": null,
"dtxp": "45",
"dtxs": "",
"pv": true
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "created_at",
"_cn": "CreatedAt",
"type": "timestamp",
"dt": "timestamp",
"uidt": "CreateTime",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": "CURRENT_TIMESTAMP",
"clen": 45,
"np": null,
"ns": null,
"dtxp": "",
"dtxs": "",
"default": "CURRENT_TIMESTAMP",
"columnDefault": "CURRENT_TIMESTAMP"
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "updated_at",
"_cn": "UpdatedAt",
"type": "timestamp",
"dt": "timestamp",
"uidt": "LastModifiedTime",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP",
"clen": 45,
"np": null,
"ns": null,
"dtxp": "",
"dtxs": "",
"default": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP",
"columnDefault": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
}
],
"columns": [
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "id",
"_cn": "Id",
"type": "integer",
"dt": "int",
"uidt": "ID",
"uip": "",
"uicn": "",
"dtx": "integer",
"ct": "int(11)",
"nrqd": false,
"rqd": true,
"ck": false,
"pk": true,
"un": true,
"ai": true,
"cdf": null,
"clen": null,
"np": 11,
"ns": 0,
"dtxp": "11",
"dtxs": ""
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "title",
"_cn": "Title",
"type": "string",
"dt": "varchar",
"uidt": "SingleLineText",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": null,
"clen": 45,
"np": null,
"ns": null,
"dtxp": "45",
"dtxs": "",
"pv": true,
"cno": "title",
"altered": 4
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "created_at",
"_cn": "CreatedAt",
"type": "timestamp",
"dt": "timestamp",
"uidt": "CreateTime",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": "CURRENT_TIMESTAMP",
"clen": 45,
"np": null,
"ns": null,
"dtxp": "",
"dtxs": "",
"default": "CURRENT_TIMESTAMP",
"columnDefault": "CURRENT_TIMESTAMP"
},
{
"validate": {
"func": [],
"args": [],
"msg": []
},
"cn": "updated_at",
"_cn": "UpdatedAt",
"type": "timestamp",
"dt": "timestamp",
"uidt": "LastModifiedTime",
"uip": "",
"uicn": "",
"dtx": "specificType",
"ct": "varchar(45)",
"nrqd": true,
"rqd": false,
"ck": false,
"pk": false,
"un": false,
"ai": false,
"cdf": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP",
"clen": 45,
"np": null,
"ns": null,
"dtxp": "",
"dtxs": "",
"default": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP",
"columnDefault": "CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
}
]
}
*
* */
const out = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('tableUpdate', opArgs);
if (this.listener) {
@ -2540,8 +2790,8 @@ export default class NcMetaMgr {
childTable: rel1.tn,
childColumn: rel1.cn,
}
},req)
await this.xcRelationColumnDelete({
}, req)
await this.xcRelationColumnDelete({
...args,
args: {
parentTable: rel2.rtn,
@ -2549,7 +2799,7 @@ export default class NcMetaMgr {
childTable: rel2.tn,
childColumn: rel2.cn,
}
},req);
}, req);
const opArgs = {
@ -2573,7 +2823,6 @@ export default class NcMetaMgr {
}
}
protected async xcVirtualRelationDelete(args: any, req): Promise<any> {

2
packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

@ -1202,7 +1202,6 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
const tagName = `${tnp}HasMany${tnc}`;
const swaggerObj = this.deleteTagFromSwaggerObj(existingModel.schema, tagName);
if (existingModel) {
this.log(`Updating model metadata for parent table '%s'`, tnp);
@ -1243,6 +1242,7 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
this.log(`Updating model metadata for child table '%s'`, tnc);
// todo: persisting old table_alias and columnAlias
const oldMeta = JSON.parse(existingModel.meta);
Object.assign(oldMeta, {
belongsTo: meta.belongsTo,
v: oldMeta.v.filter(({bt}) => !bt || bt.rtn !== tnp || bt.tn !== tnc)

2
packages/nocodb/src/lib/utils/NcHelp.ts

@ -31,7 +31,7 @@ export default class NcHelp {
}
}
}
debug.enable(enabledKeys.join(','))
}

Loading…
Cancel
Save