Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Add new database type: Timeplus (#4376)

Jove Zhong8d1d8aef4776
diff --git a/frontend/src/components/databases/display.tsx b/frontend/src/components/databases/display.tsx
index ce4e7c1298..edd2e0ba59 100644
--- a/frontend/src/components/databases/display.tsx
+++ b/frontend/src/components/databases/display.tsx
@@ -24,6 +24,8 @@ export function dbDisplayName(name: string) {
return "Google BigQuery";
case "clickhouse":
return "ClickHouse";
+ case "timeplus":
+ return "Timeplus";
case "databricks":
return "Databricks";
case "db2":
diff --git a/frontend/src/components/databases/icon.tsx b/frontend/src/components/databases/icon.tsx
index 7bc0a81458..80f665c913 100644
--- a/frontend/src/components/databases/icon.tsx
+++ b/frontend/src/components/databases/icon.tsx
@@ -7,6 +7,7 @@ import MySQLIcon from "./icons/mysql.svg";
import SnowflakeIcon from "./icons/snowflake.svg";
import DatabricksIcon from "./icons/databricks.svg";
import ClickhouseIcon from "./icons/clickhouse.svg";
+import TimeplusIcon from "./icons/timeplus.svg";
import GoogleBigQueryIcon from "./icons/googlebigquery.svg";
import TrinoIcon from "./icons/trino.svg";
import { cn } from "@/utils/cn";
@@ -20,6 +21,7 @@ export type DBLogoName =
| "snowflake"
| "databricks"
| "clickhouse"
+ | "timeplus"
| "bigquery"
| "trino";
@@ -41,6 +43,7 @@ const URLS: Record<DBLogoName, string | undefined> = {
snowflake: SnowflakeIcon,
databricks: DatabricksIcon,
clickhouse: ClickhouseIcon,
+ timeplus: TimeplusIcon,
bigquery: GoogleBigQueryIcon,
trino: TrinoIcon,
};
diff --git a/frontend/src/components/databases/icons/timeplus.svg b/frontend/src/components/databases/icons/timeplus.svg
new file mode 100644
index 0000000000..d9974349ee
--- /dev/null
+++ b/frontend/src/components/databases/icons/timeplus.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Pixelmator Pro 3.6.17 -->
+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <g id="Option2SymbolB">
+ <g id="Layer1-2">
+ <g id="Group" opacity="0.4">
+ <path id="Path" fill="#d53c97" stroke="none" d="M 17.016802 12.188573 C 17.016802 9.607646 15.86018 7.293022 14.039526 5.731081 C 13.942595 5.70038 13.844628 5.671406 13.745972 5.645189 C 13.131133 5.809095 12.54265 6.059378 11.998103 6.388559 C 13.964327 7.575191 15.281006 9.730104 15.281006 12.188573 C 15.279476 14.563734 14.033739 16.764488 11.998103 17.988243 C 12.542634 18.317537 13.131119 18.567936 13.745972 18.731958 C 13.844628 18.705742 13.942595 18.67642 14.039526 18.645721 C 15.86018 17.084126 17.016802 14.769501 17.016802 12.188573 Z"/>
+ <path id="path1" fill="#d53c97" stroke="none" d="M 13.897406 5.609659 L 13.894991 5.60759 C 13.844973 5.619663 13.7953 5.631737 13.745972 5.645189 C 13.79599 5.631737 13.847043 5.622078 13.897406 5.609659 Z"/>
+ <path id="path2" fill="#d53c97" stroke="none" d="M 1.735796 12.188573 C 1.735796 9.164728 3.728925 6.59622 6.470945 5.729357 C 7.554634 4.797861 8.856011 4.155121 10.254373 3.860756 C 9.680216 3.740549 9.095179 3.679977 8.508574 3.68 C 3.816888 3.68 -0 7.496887 -0 12.188573 C -0 16.880259 3.816888 20.697147 8.508574 20.697147 C 9.0952 20.697229 9.680255 20.636539 10.254373 20.516048 C 8.855971 20.221794 7.554568 19.579041 6.470945 18.647446 C 3.728925 17.780582 1.735796 15.213453 1.735796 12.188573 Z"/>
+ <path id="path3" fill="#d53c97" stroke="none" d="M 13.745972 18.731958 C 13.7953 18.745068 13.844973 18.757484 13.894991 18.769558 C 13.894991 18.769558 13.896715 18.769558 13.897406 18.767488 C 13.847043 18.754379 13.79599 18.745411 13.745972 18.731958 Z"/>
+ </g>
+ <path id="path4" fill="#ff3b65" stroke="none" d="M 20.508402 12.188573 C 20.508402 9.606611 19.351088 7.290262 17.5294 5.729357 C 16.301817 5.342468 14.989366 5.313629 13.745972 5.646223 C 16.636665 6.418224 18.772606 9.058484 18.772606 12.189609 C 18.772606 15.320732 16.636665 17.960991 13.745972 18.731958 C 14.98947 19.064316 16.301983 19.034998 17.5294 18.647446 C 19.419907 17.034296 20.508638 14.673781 20.508402 12.188573 Z"/>
+ <path id="path5" fill="#ff3b65" stroke="none" d="M 9.962543 18.647446 C 7.220525 17.780582 5.227395 15.213453 5.227395 12.188573 C 5.227395 9.163693 7.220525 6.59622 9.962543 5.729357 C 11.046233 4.797861 12.34761 4.155121 13.745972 3.860756 C 13.171818 3.74053 12.586779 3.679956 12.000173 3.68 C 7.308832 3.68 3.491599 7.496887 3.491599 12.188573 C 3.491599 16.880259 7.308487 20.697147 12.000173 20.697147 C 12.586799 20.697247 13.171857 20.636557 13.745972 20.516048 C 12.34757 20.221794 11.046167 19.579041 9.962543 18.647446 Z"/>
+ <path id="path6" fill="#383838" stroke="none" d="M 15.491772 3.68 C 10.800431 3.68 6.983198 7.496887 6.983198 12.188573 C 6.983198 16.880259 10.800086 20.697147 15.491772 20.697147 C 20.183456 20.697147 24 16.880259 24 12.188573 C 24 7.496887 20.183456 3.68 15.491772 3.68 Z M 22.264549 12.188573 C 22.264549 15.923018 19.226215 18.961351 15.491772 18.961351 C 11.757326 18.961351 8.718994 15.923018 8.718994 12.188573 C 8.718994 8.454128 11.757326 5.415796 15.491772 5.415796 C 19.226215 5.415796 22.264549 8.454128 22.264549 12.188573 Z"/>
+ </g>
+ </g>
+</svg>
diff --git a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap
index 8be46ab4d1..942d29bf9f 100644
--- a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap
+++ b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap
@@ -97,6 +97,15 @@ DATABASE_URL = "sqlite:////path/to/db.sqlite"
engine = sqlmodel.create_engine(DATABASE_URL)"
`;
+exports[`generateDatabaseCode > basic connections > timeplus 1`] = `
+"import os
+import sqlalchemy
+
+_password = os.environ.get("TIMEPLUS_PASSWORD", "")
+DATABASE_URL = f"timeplus://default:{_password}@localhost:8123"
+engine = sqlalchemy.create_engine(DATABASE_URL)"
+`;
+
exports[`generateDatabaseCode > basic connections > trino 1`] = `
"import os
import sqlmodel
@@ -174,6 +183,17 @@ engine = sqlmodel.create_engine(
)"
`;
+exports[`generateDatabaseCode > connections with secrets > timeplus with all connection details as secrets 1`] = `
+"import os
+import sqlalchemy
+
+_password = os.environ.get("ENV_PASSWORD")
+_username = os.environ.get("ENV_USER")
+_host = os.environ.get("ENV_HOST")
+DATABASE_URL = f"timeplus://{_username}:{_password}@{_host}:8123"
+engine = sqlalchemy.create_engine(DATABASE_URL)"
+`;
+
exports[`generateDatabaseCode > edge cases > ENV with special chars SQLModel 1`] = `
"import os
import sqlmodel
@@ -355,6 +375,24 @@ DATABASE_URL = "sqlite:///"
engine = sqlmodel.create_engine(DATABASE_URL)"
`;
+exports[`generateDatabaseCode > edge cases > timeplus connect with minimal config 1`] = `
+"import os
+import sqlalchemy
+
+_password = os.environ.get("TIMEPLUS_PASSWORD", "")
+DATABASE_URL = f"timeplus://default:{_password}@localhost:"
+engine = sqlalchemy.create_engine(DATABASE_URL)"
+`;
+
+exports[`generateDatabaseCode > edge cases > timeplus with no port 1`] = `
+"import os
+import sqlalchemy
+
+_password = os.environ.get("TIMEPLUS_PASSWORD", "")
+DATABASE_URL = f"timeplus://default:{_password}@localhost:"
+engine = sqlalchemy.create_engine(DATABASE_URL)"
+`;
+
exports[`generateDatabaseCode > edge cases > trino with async support 1`] = `
"import aiotrino
import os
diff --git a/frontend/src/components/editor/database/__tests__/as-code.test.ts b/frontend/src/components/editor/database/__tests__/as-code.test.ts
index 70c798c3ad..865b5187f2 100644
--- a/frontend/src/components/editor/database/__tests__/as-code.test.ts
+++ b/frontend/src/components/editor/database/__tests__/as-code.test.ts
@@ -64,6 +64,14 @@ describe("generateDatabaseCode", () => {
secure: false,
};
+ const timeplusConnection: DatabaseConnection = {
+ type: "timeplus",
+ host: "localhost",
+ port: 8123,
+ username: "default",
+ password: "",
+ };
+
const chdbConnection: DatabaseConnection = {
type: "chdb",
database: "file:///path/to/db.chdb",
@@ -92,6 +100,7 @@ describe("generateDatabaseCode", () => {
["bigquery", bigqueryConnection, "sqlmodel"],
["clickhouse", clickhouseConnection, "clickhouse_connect"],
["chdb", chdbConnection, "chdb"],
+ ["timeplus", timeplusConnection, "sqlalchemy"],
["trino", trinoConnection, "sqlmodel"],
])("%s", (name, connection, orm) => {
expect(
@@ -149,6 +158,16 @@ describe("generateDatabaseCode", () => {
},
"clickhouse_connect",
],
+ [
+ "timeplus with all connection details as secrets",
+ {
+ ...timeplusConnection,
+ host: prefixSecret("ENV_HOST"),
+ username: prefixSecret("ENV_USER"),
+ password: prefixSecret("ENV_PASSWORD"),
+ },
+ "sqlalchemy",
+ ],
])("%s", (name, connection, orm) => {
expect(
generateDatabaseCode(connection, orm as ConnectionLibrary),
@@ -201,6 +220,15 @@ describe("generateDatabaseCode", () => {
},
"clickhouse_connect",
],
+ [
+ "timeplus connect with minimal config",
+ {
+ ...timeplusConnection,
+ port: undefined,
+ password: "",
+ },
+ "sqlalchemy",
+ ],
[
"postgres with unicode",
{
@@ -318,6 +346,14 @@ describe("generateDatabaseCode", () => {
},
"clickhouse_connect",
],
+ [
+ "timeplus with no port",
+ {
+ ...timeplusConnection,
+ port: undefined,
+ },
+ "sqlalchemy",
+ ],
[
"chdb with no database",
{
diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsx
index 368ffbf147..e5a2182d3a 100644
--- a/frontend/src/components/editor/database/add-database-form.tsx
+++ b/frontend/src/components/editor/database/add-database-form.tsx
@@ -14,6 +14,7 @@ import {
BigQueryConnectionSchema,
type DatabaseConnection,
ClickhouseConnectionSchema,
+ TimeplusConnectionSchema,
ChdbConnectionSchema,
TrinoConnectionSchema,
} from "./schemas";
@@ -111,6 +112,16 @@ const SCHEMAS = [
preferred: "clickhouse_connect",
},
},
+ {
+ name: "Timeplus",
+ schema: TimeplusConnectionSchema,
+ color: "#B83280",
+ logo: "timeplus",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
{
name: "BigQuery",
schema: BigQueryConnectionSchema,
diff --git a/frontend/src/components/editor/database/as-code.ts b/frontend/src/components/editor/database/as-code.ts
index 08ac8bae18..cef5cf1674 100644
--- a/frontend/src/components/editor/database/as-code.ts
+++ b/frontend/src/components/editor/database/as-code.ts
@@ -352,6 +352,30 @@ ${formatUrlParams(params, (inner) => ` ${inner}`)},
`);
}
}
+class TimeplusGenerator extends CodeGenerator<"timeplus"> {
+ generateImports(): string[] {
+ return [];
+ }
+
+ generateConnectionCode(): string {
+ const password = this.secrets.printPassword(
+ this.connection.password,
+ "TIMEPLUS_PASSWORD",
+ true,
+ );
+ const username = this.secrets.printInFString(
+ "username",
+ this.connection.username,
+ );
+ const host = this.secrets.printInFString("host", this.connection.host);
+ const port = this.secrets.printInFString("port", this.connection.port);
+
+ return dedent(`
+ DATABASE_URL = f"timeplus://${username}:${password}@${host}:${port}"
+ engine = ${this.orm}.create_engine(DATABASE_URL)
+ `);
+ }
+}
class ChDBGenerator extends CodeGenerator<"chdb"> {
generateImports(): string[] {
@@ -423,6 +447,8 @@ class CodeGeneratorFactory {
return new DuckDBGenerator(connection, orm, this.secrets);
case "clickhouse_connect":
return new ClickHouseGenerator(connection, orm, this.secrets);
+ case "timeplus":
+ return new TimeplusGenerator(connection, orm, this.secrets);
case "chdb":
return new ChDBGenerator(connection, orm, this.secrets);
case "trino":
diff --git a/frontend/src/components/editor/database/schemas.ts b/frontend/src/components/editor/database/schemas.ts
index 2cd91bb223..b72bf6469c 100644
--- a/frontend/src/components/editor/database/schemas.ts
+++ b/frontend/src/components/editor/database/schemas.ts
@@ -223,6 +223,16 @@ export const ClickhouseConnectionSchema = z
})
.describe(FieldOptions.of({ direction: "two-columns" }));
+export const TimeplusConnectionSchema = z
+ .object({
+ type: z.literal("timeplus"),
+ host: hostField().default("localhost"),
+ port: portField(8123).optional(),
+ username: usernameField().default("default"),
+ password: passwordField().default(""),
+ })
+ .describe(FieldOptions.of({ direction: "two-columns" }));
+
export const ChdbConnectionSchema = z
.object({
type: z.literal("chdb"),
@@ -257,6 +267,7 @@ export const DatabaseConnectionSchema = z.discriminatedUnion("type", [
SnowflakeConnectionSchema,
BigQueryConnectionSchema,
ClickhouseConnectionSchema,
+ TimeplusConnectionSchema,
ChdbConnectionSchema,
TrinoConnectionSchema,
]);
diff --git a/marimo/_dependencies/dependencies.py b/marimo/_dependencies/dependencies.py
index 51336f973f..674efd1852 100644
--- a/marimo/_dependencies/dependencies.py
+++ b/marimo/_dependencies/dependencies.py
@@ -171,6 +171,7 @@ class DependencyManager:
duckdb = Dependency("duckdb")
chdb = Dependency("chdb")
clickhouse_connect = Dependency("clickhouse_connect")
+ timeplus_connect = Dependency("timeplus_connect")
sqlglot = Dependency("sqlglot")
pillow = Dependency("PIL")
plotly = Dependency("plotly")
diff --git a/marimo/_sql/engines/sqlalchemy.py b/marimo/_sql/engines/sqlalchemy.py
index 6890782b66..80c2ad5956 100644
--- a/marimo/_sql/engines/sqlalchemy.py
+++ b/marimo/_sql/engines/sqlalchemy.py
@@ -142,6 +142,7 @@ class SQLAlchemyEngine(SQLEngine):
dialect_queries = {
"postgresql": "SELECT current_database()",
"mssql": "SELECT DB_NAME()",
+ "timeplus": "SELECT current_database()",
}
# Try to get the database name by querying the database directly