Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
50
Frontend-Learner/node_modules/db0/dist/connectors/planetscale.mjs
generated
vendored
Normal file
50
Frontend-Learner/node_modules/db0/dist/connectors/planetscale.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { Client } from "@planetscale/database";
|
||||
import { BoundableStatement } from "./_internal/statement.mjs";
|
||||
export default function planetscaleConnector(opts) {
|
||||
let _client;
|
||||
function getClient() {
|
||||
if (_client) {
|
||||
return _client;
|
||||
}
|
||||
const client = new Client(opts);
|
||||
_client = client;
|
||||
return client;
|
||||
}
|
||||
// Discussion on how @planetscale/database client works:
|
||||
// https://github.com/drizzle-team/drizzle-orm/issues/1743#issuecomment-1879479647
|
||||
const query = (sql, params) => getClient().execute(sql, params);
|
||||
return {
|
||||
name: "planetscale",
|
||||
dialect: "mysql",
|
||||
getInstance: () => getClient(),
|
||||
exec: (sql) => query(sql),
|
||||
prepare: (sql) => new StatementWrapper(sql, query),
|
||||
dispose: () => {
|
||||
_client = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
class StatementWrapper extends BoundableStatement {
|
||||
#query;
|
||||
#sql;
|
||||
constructor(sql, query) {
|
||||
super();
|
||||
this.#sql = sql;
|
||||
this.#query = query;
|
||||
}
|
||||
async all(...params) {
|
||||
const res = await this.#query(this.#sql, params);
|
||||
return res.rows;
|
||||
}
|
||||
async run(...params) {
|
||||
const res = await this.#query(this.#sql, params);
|
||||
return {
|
||||
success: true,
|
||||
...res
|
||||
};
|
||||
}
|
||||
async get(...params) {
|
||||
const res = await this.#query(this.#sql, params);
|
||||
return res.rows[0];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue