penambahan web socket

This commit is contained in:
2025-09-18 19:01:22 +07:00
parent 1d053646a9
commit d7bb2eb5bb
15070 changed files with 2402916 additions and 0 deletions

No files matched your search

@@ -0,0 +1,36 @@
import { entityKind, Logger, RelationalSchemaConfig, type Query, type TablesRelationalConfig } from "drizzle-orm";
import { SQLiteAsyncDialect, SQLiteSession, SQLitePreparedQuery } from "drizzle-orm/sqlite-core";
import type { PreparedQueryConfig, SelectedFieldsOrdered, SQLiteExecuteMethod, SQLiteTransactionConfig } from "drizzle-orm/sqlite-core";
import type { Database, Statement } from "db0";
export interface DB0SessionOptions {
logger?: Logger;
}
export declare class DB0Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<"async", unknown, TFullSchema, TSchema> {
private db;
private schema;
private options;
dialect: SQLiteAsyncDialect;
private logger;
constructor(db: Database, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: DB0SessionOptions);
prepareQuery(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: (rows: unknown[][]) => unknown): DB0PreparedQuery;
transaction<T>(transaction: (tx: any) => T | Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
}
export declare class DB0PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
type: "async";
run: Awaited<ReturnType<Statement["run"]>>;
all: T["all"];
get: T["get"];
values: T["values"];
execute: T["execute"];
}> {
private stmt;
private logger;
static readonly [entityKind]: string;
constructor(stmt: Statement, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: (rows: unknown[][]) => unknown);
run(): Promise<{
success: boolean;
}>;
all(): Promise<unknown[]>;
get(): Promise<unknown>;
values(): Promise<never>;
}
@@ -0,0 +1,55 @@
import {
entityKind,
NoopLogger
} from "drizzle-orm";
import {
SQLiteSession,
SQLitePreparedQuery
} from "drizzle-orm/sqlite-core";
export class DB0Session extends SQLiteSession {
constructor(db, dialect, schema, options = {}) {
super(dialect);
this.db = db;
this.schema = schema;
this.options = options;
this.logger = options.logger ?? new NoopLogger();
}
dialect;
logger;
prepareQuery(query, fields, executeMethod, customResultMapper) {
const stmt = this.db.prepare(query.sql);
return new DB0PreparedQuery(
stmt,
query,
this.logger,
fields,
executeMethod,
customResultMapper
);
}
// TODO: Implement batch
// TODO: Implement transaction
transaction(transaction, config) {
throw new Error("transaction is not implemented!");
}
}
export class DB0PreparedQuery extends SQLitePreparedQuery {
constructor(stmt, query, logger, fields, executeMethod, customResultMapper) {
super("async", executeMethod, query);
this.stmt = stmt;
this.logger = logger;
}
static [entityKind] = "DB0PreparedQuery";
run() {
return this.stmt.run(...this.query.params);
}
all() {
return this.stmt.all(...this.query.params);
}
get() {
return this.stmt.get(...this.query.params);
}
values() {
return Promise.reject(new Error("values is not implemented!"));
}
}
@@ -0,0 +1,3 @@
import { AnyColumn, SelectedFieldsOrdered } from "drizzle-orm";
/** @internal */
export declare function mapResultRow<TResult>(columns: SelectedFieldsOrdered<AnyColumn>, row: unknown[], joinsNotNullableMap: Record<string, boolean> | undefined): TResult;
@@ -0,0 +1,51 @@
import {
getTableName,
is,
Column,
SQL
} from "drizzle-orm";
export function mapResultRow(columns, row, joinsNotNullableMap) {
const nullifyMap = {};
const result = columns.reduce(
(result2, { path, field }, columnIndex) => {
let decoder;
if (is(field, Column)) {
decoder = field;
} else if (is(field, SQL)) {
decoder = "decoder" in field && field.decoder;
} else {
decoder = "decoder" in field.sql && field.sql.decoder;
}
let node = result2;
for (const [pathChunkIndex, pathChunk] of path.entries()) {
if (pathChunkIndex < path.length - 1) {
if (!(pathChunk in node)) {
node[pathChunk] = {};
}
node = node[pathChunk];
} else {
const rawValue = row[columnIndex];
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
const objectName = path[0];
if (!(objectName in nullifyMap)) {
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
nullifyMap[objectName] = false;
}
}
}
}
return result2;
},
{}
);
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
result[objectName] = null;
}
}
}
return result;
}
@@ -0,0 +1,4 @@
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
import type { Database } from "db0";
export type DrizzleDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = BaseSQLiteDatabase<"async", any, TSchema>;
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(db: Database): DrizzleDatabase<TSchema>;
@@ -0,0 +1,16 @@
import {
BaseSQLiteDatabase,
SQLiteAsyncDialect
} from "drizzle-orm/sqlite-core";
import { DB0Session } from "./_session.mjs";
export function drizzle(db) {
const schema = void 0;
const dialect = new SQLiteAsyncDialect();
const session = new DB0Session(db, dialect, schema);
return new BaseSQLiteDatabase(
"async",
dialect,
session,
schema
);
}