@difizen/libro-sql-cell 0.0.0-snapshot-20241017072317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/index.d.ts +2 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +1 -0
- package/es/index.less +116 -0
- package/es/libro-formatter-sql-magic-contribution.d.ts +25 -0
- package/es/libro-formatter-sql-magic-contribution.d.ts.map +1 -0
- package/es/libro-formatter-sql-magic-contribution.js +50 -0
- package/es/libro-formatter-sql-trans-contribution.d.ts +13 -0
- package/es/libro-formatter-sql-trans-contribution.d.ts.map +1 -0
- package/es/libro-formatter-sql-trans-contribution.js +26 -0
- package/es/libro-sql-cell-color-registry.d.ts +6 -0
- package/es/libro-sql-cell-color-registry.d.ts.map +1 -0
- package/es/libro-sql-cell-color-registry.js +57 -0
- package/es/libro-sql-cell-contribution.d.ts +15 -0
- package/es/libro-sql-cell-contribution.d.ts.map +1 -0
- package/es/libro-sql-cell-contribution.js +75 -0
- package/es/libro-sql-cell-model.d.ts +33 -0
- package/es/libro-sql-cell-model.d.ts.map +1 -0
- package/es/libro-sql-cell-model.js +161 -0
- package/es/libro-sql-cell-protocol.d.ts +16 -0
- package/es/libro-sql-cell-protocol.d.ts.map +1 -0
- package/es/libro-sql-cell-protocol.js +1 -0
- package/es/libro-sql-cell-script.d.ts +4 -0
- package/es/libro-sql-cell-script.d.ts.map +1 -0
- package/es/libro-sql-cell-script.js +12 -0
- package/es/libro-sql-cell-view.d.ts +42 -0
- package/es/libro-sql-cell-view.d.ts.map +1 -0
- package/es/libro-sql-cell-view.js +583 -0
- package/es/libro-sql-utils.d.ts +3 -0
- package/es/libro-sql-utils.d.ts.map +1 -0
- package/es/libro-sql-utils.js +33 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +25 -0
- package/package.json +65 -0
- package/src/index.less +120 -0
- package/src/index.spec.ts +9 -0
- package/src/index.ts +1 -0
- package/src/libro-formatter-sql-magic-contribution.ts +66 -0
- package/src/libro-formatter-sql-trans-contribution.ts +22 -0
- package/src/libro-sql-cell-color-registry.ts +35 -0
- package/src/libro-sql-cell-contribution.ts +46 -0
- package/src/libro-sql-cell-model.ts +115 -0
- package/src/libro-sql-cell-protocol.ts +20 -0
- package/src/libro-sql-cell-script.ts +6 -0
- package/src/libro-sql-cell-view.tsx +560 -0
- package/src/libro-sql-utils.ts +22 -0
- package/src/module.ts +38 -0
package/es/module.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CellOptions, LibroModule } from '@difizen/libro-jupyter';
|
|
2
|
+
import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
import { FormatterSqlMagicContribution } from "./libro-formatter-sql-magic-contribution.js";
|
|
5
|
+
import { FormatterStringTransSqlContribution } from "./libro-formatter-sql-trans-contribution.js";
|
|
6
|
+
import { LibroSQLCellColorRegistry } from "./libro-sql-cell-color-registry.js";
|
|
7
|
+
import { SqlCellContribution } from "./libro-sql-cell-contribution.js";
|
|
8
|
+
import { LibroSqlCellModel } from "./libro-sql-cell-model.js";
|
|
9
|
+
import { LibroSqlCellModelFactory } from "./libro-sql-cell-protocol.js";
|
|
10
|
+
import { SqlScript } from "./libro-sql-cell-script.js";
|
|
11
|
+
import { LibroSqlCellView } from "./libro-sql-cell-view.js";
|
|
12
|
+
export var LibroSqlCellModule = ManaModule.create().register(SqlCellContribution, LibroSqlCellView, LibroSqlCellModel, LibroSQLCellColorRegistry, FormatterSqlMagicContribution, FormatterStringTransSqlContribution, SqlScript, {
|
|
13
|
+
token: LibroSqlCellModelFactory,
|
|
14
|
+
useFactory: function useFactory(ctx) {
|
|
15
|
+
return function (options) {
|
|
16
|
+
var child = ctx.container.createChild();
|
|
17
|
+
child.register({
|
|
18
|
+
token: CellOptions,
|
|
19
|
+
useValue: options
|
|
20
|
+
});
|
|
21
|
+
var model = child.get(LibroSqlCellModel);
|
|
22
|
+
return model;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}).dependOn(LibroModule, LibroRenderMimeModule);
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-sql-cell",
|
|
3
|
+
"version": "0.0.0-snapshot-20241017072317",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook"
|
|
8
|
+
],
|
|
9
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"typings": "./es/index.d.ts",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"typings": "./es/mock/index.d.ts",
|
|
19
|
+
"default": "./es/mock/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./es/mock": {
|
|
22
|
+
"typings": "./es/mock/index.d.ts",
|
|
23
|
+
"default": "./es/mock/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "es/index.js",
|
|
28
|
+
"module": "es/index.js",
|
|
29
|
+
"typings": "es/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"es",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@difizen/libro-code-editor": "0.0.0-snapshot-20241017072317",
|
|
36
|
+
"@difizen/libro-jupyter": "0.0.0-snapshot-20241017072317",
|
|
37
|
+
"@difizen/libro-rendermime": "0.0.0-snapshot-20241017072317",
|
|
38
|
+
"@difizen/libro-common": "0.0.0-snapshot-20241017072317",
|
|
39
|
+
"@ant-design/icons": "^5.1.0",
|
|
40
|
+
"@difizen/mana-app": "latest",
|
|
41
|
+
"@difizen/mana-l10n": "latest"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=16",
|
|
45
|
+
"antd": "^5.8.6"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/react": "^18.2.25",
|
|
49
|
+
"@types/uuid": "^9.0.2",
|
|
50
|
+
"@types/react-dom": "^18.2.4"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"setup": "father build",
|
|
54
|
+
"build": "father build",
|
|
55
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
56
|
+
"test:vitest": "vitest run",
|
|
57
|
+
"test:jest": "jest",
|
|
58
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
59
|
+
"coverage:vitest": "vitest run --coverage",
|
|
60
|
+
"coverage:jest": "jest --coverage",
|
|
61
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
62
|
+
"lint:eslint": "eslint src",
|
|
63
|
+
"typecheck:tsc": "tsc --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/index.less
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The prefix to use on all css classes from ant.
|
|
2
|
+
@ant-prefix: ant;
|
|
3
|
+
|
|
4
|
+
.libro-sql-cell-header {
|
|
5
|
+
height: 36px;
|
|
6
|
+
border-bottom: 1px solid var(--mana-libro-code-border-color);
|
|
7
|
+
display: flex;
|
|
8
|
+
|
|
9
|
+
span {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.libro-sql-source {
|
|
15
|
+
padding: 0 16px;
|
|
16
|
+
border-right: 1px solid var(--mana-libro-cell-border-color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.libro-sql-variable-name-input {
|
|
20
|
+
width: 120px !important;
|
|
21
|
+
height: 32px;
|
|
22
|
+
margin-left: 6px;
|
|
23
|
+
color: var(--mana-libro-cell-header-content);
|
|
24
|
+
border: 1px solid var(--mana-libro-cell-border-color) !important;
|
|
25
|
+
background: var(--mana-libro-popover-background-color);
|
|
26
|
+
border-radius: 6px !important;
|
|
27
|
+
box-shadow: unset !important;
|
|
28
|
+
&.@{ant-prefix}-input-status-warning {
|
|
29
|
+
border-color: #faad14 !important;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.libro-sql-variable-name-title {
|
|
34
|
+
padding-left: 16px;
|
|
35
|
+
color: var(--mana-libro-cell-header-title);
|
|
36
|
+
font-weight: 400;
|
|
37
|
+
font-size: 14px;
|
|
38
|
+
font-family: SFProText;
|
|
39
|
+
line-height: 36px;
|
|
40
|
+
letter-spacing: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.libro-sql-source-content,
|
|
44
|
+
.libro-sql-variable-content {
|
|
45
|
+
padding-left: 3px;
|
|
46
|
+
color: var(--mana-libro-cell-header-content);
|
|
47
|
+
font-weight: 400;
|
|
48
|
+
font-size: 14px;
|
|
49
|
+
font-family: SFProText;
|
|
50
|
+
line-height: 36px;
|
|
51
|
+
letter-spacing: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.libro-sql-variable-content {
|
|
55
|
+
padding-left: 18px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.libro-sql-variable-name {
|
|
59
|
+
display: flex;
|
|
60
|
+
margin-left: 8px;
|
|
61
|
+
align-items: center;
|
|
62
|
+
|
|
63
|
+
svg {
|
|
64
|
+
margin-left: 4px;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.libro-sql-input-save,
|
|
69
|
+
.libro-sql-input-cancel {
|
|
70
|
+
width: 28px;
|
|
71
|
+
height: 20px;
|
|
72
|
+
color: #1890ff;
|
|
73
|
+
font-weight: 400;
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
letter-spacing: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.libro-sql-input-save {
|
|
79
|
+
margin-left: 8px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.libro-sql-edit-icon {
|
|
83
|
+
color: #bdc0c4 !important;
|
|
84
|
+
|
|
85
|
+
&:hover {
|
|
86
|
+
color: #1590ff !important;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.libro-sql-popover-container {
|
|
91
|
+
padding-top: 10px !important;
|
|
92
|
+
.@{ant-prefix}-popover-inner {
|
|
93
|
+
border-radius: 8px;
|
|
94
|
+
}
|
|
95
|
+
.@{ant-prefix}-popover-inner-content {
|
|
96
|
+
height: 100% !important;
|
|
97
|
+
text-align: right;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.@{ant-prefix}-popover-content {
|
|
101
|
+
transform: translateX(-18px) !important;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.libro-sql-input-warning-text {
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
margin-top: 4px;
|
|
109
|
+
color: #faad14;
|
|
110
|
+
font-weight: 400;
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.libro-sql-input-button {
|
|
115
|
+
margin-top: 12px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.libro-sql-variable-name-popover {
|
|
119
|
+
vertical-align: middle;
|
|
120
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
4
|
+
import { FormatterContribution } from '@difizen/libro-jupyter';
|
|
5
|
+
import type {
|
|
6
|
+
DefaultEncodedFormatter,
|
|
7
|
+
DefaultDecodedFormatter,
|
|
8
|
+
} from '@difizen/libro-jupyter';
|
|
9
|
+
import { singleton } from '@difizen/mana-app';
|
|
10
|
+
|
|
11
|
+
export interface SqlDecodedFormatter extends DefaultDecodedFormatter {
|
|
12
|
+
result_variable?: string;
|
|
13
|
+
db_id?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@singleton({ contrib: FormatterContribution })
|
|
17
|
+
export class FormatterSqlMagicContribution
|
|
18
|
+
implements FormatterContribution<SqlDecodedFormatter>
|
|
19
|
+
{
|
|
20
|
+
formatter = 'formatter-sql-magic';
|
|
21
|
+
formatterOptions?: object;
|
|
22
|
+
|
|
23
|
+
canHandle = (libroFormatter: string) => {
|
|
24
|
+
return libroFormatter === this.formatter ? 100 : 1;
|
|
25
|
+
};
|
|
26
|
+
encode = (source: SqlDecodedFormatter) => {
|
|
27
|
+
const sqlJson = {
|
|
28
|
+
result_variable: source.result_variable,
|
|
29
|
+
db_id: source.db_id,
|
|
30
|
+
sql_script: source.value,
|
|
31
|
+
};
|
|
32
|
+
const sqlEncodedValue = `%%sql \n${JSON.stringify(sqlJson)}`;
|
|
33
|
+
return {
|
|
34
|
+
source: sqlEncodedValue,
|
|
35
|
+
metadata: {
|
|
36
|
+
libroFormatter: this.formatter,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
41
|
+
const value = concatMultilineString(formatterValue.source);
|
|
42
|
+
if (value.startsWith('%%sql \n')) {
|
|
43
|
+
const run = value.split('%%sql \n')[1];
|
|
44
|
+
try {
|
|
45
|
+
const runValue = JSON.parse(run);
|
|
46
|
+
const result_variable: string = runValue.result_variable;
|
|
47
|
+
const db_id: string = runValue.db_id;
|
|
48
|
+
const codeValue: string = runValue.sql_script;
|
|
49
|
+
return {
|
|
50
|
+
result_variable,
|
|
51
|
+
value: codeValue,
|
|
52
|
+
db_id,
|
|
53
|
+
};
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.warn('🚀 ~ e:', e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
value: '',
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
validate = (source: SqlDecodedFormatter): source is SqlDecodedFormatter => {
|
|
64
|
+
return 'result_variable' in source && 'sql_script' in source && 'db_id' in source;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { FormatterTransContribution } from '@difizen/libro-jupyter';
|
|
3
|
+
import type { DefaultDecodedFormatter } from '@difizen/libro-jupyter';
|
|
4
|
+
import { singleton } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
import type { SqlDecodedFormatter } from './libro-formatter-sql-magic-contribution.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: FormatterTransContribution })
|
|
9
|
+
export class FormatterStringTransSqlContribution
|
|
10
|
+
implements FormatterTransContribution<DefaultDecodedFormatter, SqlDecodedFormatter>
|
|
11
|
+
{
|
|
12
|
+
origin = 'formatter-string';
|
|
13
|
+
target = 'formatter-sql-magic';
|
|
14
|
+
priority = 100;
|
|
15
|
+
|
|
16
|
+
decodedValueTrans = (source: DefaultDecodedFormatter) => {
|
|
17
|
+
return {
|
|
18
|
+
...source,
|
|
19
|
+
result_variable: source['result_variable'] || 'df_from_trans',
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ColorRegistry } from '@difizen/mana-app';
|
|
2
|
+
import { Color, ColorContribution, singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
@singleton({ contrib: ColorContribution })
|
|
5
|
+
export class LibroSQLCellColorRegistry implements ColorContribution {
|
|
6
|
+
registerColors(colors: ColorRegistry): void {
|
|
7
|
+
colors.register(
|
|
8
|
+
{
|
|
9
|
+
id: 'libro.sql.tab',
|
|
10
|
+
defaults: { dark: '#B2B2B3', light: Color.rgba(0, 10, 26, 0.68) },
|
|
11
|
+
description: '',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: 'libro.sql.tab.background',
|
|
15
|
+
defaults: { dark: '#1C1C1D', light: '#FAFAFB' },
|
|
16
|
+
description: '',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'libro.sql.button.border',
|
|
20
|
+
defaults: { dark: '#505559', light: Color.rgba(0, 10, 26, 0.1) },
|
|
21
|
+
description: '',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'libro.sql.button.background',
|
|
25
|
+
defaults: { dark: '#2F3032', light: '#FFFFFF' },
|
|
26
|
+
description: '',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'libro.sql.button.text.color',
|
|
30
|
+
defaults: { dark: '#BDC0C4', light: Color.rgba(0, 10, 26, 0.68) },
|
|
31
|
+
description: '',
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-jupyter';
|
|
4
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-jupyter';
|
|
5
|
+
import { inject } from '@difizen/mana-app';
|
|
6
|
+
import { singleton } from '@difizen/mana-app';
|
|
7
|
+
|
|
8
|
+
import { LibroSqlCellModelFactory } from './libro-sql-cell-protocol.js';
|
|
9
|
+
import { LibroSqlCellView } from './libro-sql-cell-view.js';
|
|
10
|
+
|
|
11
|
+
@singleton({
|
|
12
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution],
|
|
13
|
+
})
|
|
14
|
+
export class SqlCellContribution
|
|
15
|
+
implements CellModelContribution, CellViewContribution, LanguageSpecContribution
|
|
16
|
+
{
|
|
17
|
+
@inject(LibroSqlCellModelFactory)
|
|
18
|
+
sqlCellModelFactory: LibroSqlCellModelFactory;
|
|
19
|
+
|
|
20
|
+
cellMeta: CellMeta = {
|
|
21
|
+
type: 'sql',
|
|
22
|
+
name: 'SQL',
|
|
23
|
+
order: 'e',
|
|
24
|
+
nbformatType: 'code',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
canHandle(options: CellOptions, libroType?: string): number {
|
|
28
|
+
return libroType === this.cellMeta.type ? 2000 : -1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async createModel(options: CellOptions): Promise<CellModel> {
|
|
32
|
+
const model = this.sqlCellModelFactory(options);
|
|
33
|
+
return model;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
view = LibroSqlCellView;
|
|
37
|
+
|
|
38
|
+
registerLanguageSpec = (register: LanguageSpecRegistry) => {
|
|
39
|
+
register.registerLanguageSpec({
|
|
40
|
+
name: 'SQL',
|
|
41
|
+
language: 'sql-odps',
|
|
42
|
+
mime: 'application/vnd.libro.sql+json',
|
|
43
|
+
ext: ['.sql'],
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ICellMetadata,
|
|
3
|
+
ICodeCell,
|
|
4
|
+
ICodeCellMetadata,
|
|
5
|
+
} from '@difizen/libro-common';
|
|
6
|
+
import type { ExecutionCount } from '@difizen/libro-common';
|
|
7
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-jupyter';
|
|
8
|
+
import type { ExecutableCellModel } from '@difizen/libro-jupyter';
|
|
9
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
10
|
+
import { Emitter, inject, prop, transient, ViewManager } from '@difizen/mana-app';
|
|
11
|
+
|
|
12
|
+
import type { SqlDecodedFormatter } from './libro-formatter-sql-magic-contribution.js';
|
|
13
|
+
|
|
14
|
+
export interface SqlCellMetadata extends ICodeCellMetadata {
|
|
15
|
+
resultVariable: string;
|
|
16
|
+
}
|
|
17
|
+
@transient()
|
|
18
|
+
export class LibroSqlCellModel extends LibroCellModel implements ExecutableCellModel {
|
|
19
|
+
@prop()
|
|
20
|
+
resultVariable: string | undefined;
|
|
21
|
+
@prop()
|
|
22
|
+
dbId: string | undefined;
|
|
23
|
+
@prop()
|
|
24
|
+
executeCount: ExecutionCount;
|
|
25
|
+
@prop()
|
|
26
|
+
executing: boolean;
|
|
27
|
+
@prop()
|
|
28
|
+
hasOutputHidden: boolean;
|
|
29
|
+
@prop()
|
|
30
|
+
hasOutputsScrolled: boolean;
|
|
31
|
+
|
|
32
|
+
@prop()
|
|
33
|
+
kernelExecuting = false;
|
|
34
|
+
|
|
35
|
+
@prop()
|
|
36
|
+
hasExecutedSuccess = false;
|
|
37
|
+
@prop()
|
|
38
|
+
hasExecutedError = false;
|
|
39
|
+
@prop()
|
|
40
|
+
override metadata: Partial<SqlCellMetadata | ICellMetadata>;
|
|
41
|
+
|
|
42
|
+
declare _decodeObject: SqlDecodedFormatter;
|
|
43
|
+
|
|
44
|
+
// Emitter Msg
|
|
45
|
+
msgChangeEmitter: Emitter<any>;
|
|
46
|
+
|
|
47
|
+
get msgChange(): ManaEvent<any> {
|
|
48
|
+
return this.msgChangeEmitter.event;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
viewManager: ViewManager;
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
@inject(CellOptions) options: CellOptions,
|
|
55
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
56
|
+
) {
|
|
57
|
+
super(options);
|
|
58
|
+
this.viewManager = viewManager;
|
|
59
|
+
this.executing = false;
|
|
60
|
+
this.msgChangeEmitter = new Emitter<any>();
|
|
61
|
+
this.executeCount = (options.cell as ICodeCell).execution_count || null;
|
|
62
|
+
this.mimeType = 'application/vnd.libro.sql+json';
|
|
63
|
+
this.hasOutputHidden = false;
|
|
64
|
+
this.hasOutputsScrolled = false;
|
|
65
|
+
this.libroFormatType = 'formatter-sql-magic';
|
|
66
|
+
this.metadata = {
|
|
67
|
+
...options?.cell?.metadata,
|
|
68
|
+
libroFormatter: this.libroFormatType,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override toJSON(): Omit<ICodeCell, 'outputs'> {
|
|
73
|
+
// const outputs = this.outputArea?.toJSON() ?? this.outputs;
|
|
74
|
+
return {
|
|
75
|
+
id: this.id,
|
|
76
|
+
cell_type: this.type,
|
|
77
|
+
source: this.source,
|
|
78
|
+
metadata: this.metadata,
|
|
79
|
+
execution_count: this.executeCount,
|
|
80
|
+
// outputs: this.outputs,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override set decodeObject(data: SqlDecodedFormatter) {
|
|
85
|
+
this.value = data.value;
|
|
86
|
+
this.resultVariable = data.result_variable;
|
|
87
|
+
this.dbId = data.db_id;
|
|
88
|
+
this._decodeObject = data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override get decodeObject() {
|
|
92
|
+
return {
|
|
93
|
+
...this._decodeObject,
|
|
94
|
+
value: this.value,
|
|
95
|
+
result_variable: this.resultVariable || this._decodeObject.result_variable,
|
|
96
|
+
db_id: this.dbId || this._decodeObject.db_id,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
clearExecution = () => {
|
|
101
|
+
this.executeCount = null;
|
|
102
|
+
this.executing = false;
|
|
103
|
+
this.kernelExecuting = false;
|
|
104
|
+
this.metadata['execution'] = {};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
override dispose() {
|
|
108
|
+
super.dispose();
|
|
109
|
+
this.msgChangeEmitter.dispose();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getSource() {
|
|
113
|
+
return this.value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CellOptions, CellView } from '@difizen/libro-jupyter';
|
|
2
|
+
|
|
3
|
+
import type { LibroSqlCellModel } from './libro-sql-cell-model.js';
|
|
4
|
+
|
|
5
|
+
export type LibroSqlCellModelFactory = (options: CellOptions) => LibroSqlCellModel;
|
|
6
|
+
export const LibroSqlCellModelFactory = Symbol('LibroSqlCellModelFactory');
|
|
7
|
+
|
|
8
|
+
export interface VisAnalysis {
|
|
9
|
+
addAnalysisCell: (cellView: CellView, dfName?: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DatabaseConfig {
|
|
13
|
+
db_type: string;
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
password: string;
|
|
17
|
+
host: string;
|
|
18
|
+
port: number;
|
|
19
|
+
database: string;
|
|
20
|
+
}
|