测试
a month ago
中文
a month ago
Suno Ai لحن
2 months ago
2
4 months ago
développement web
4 months ago
none
5 months ago
it
5 months ago
qwe
5 months ago
mony
5 months ago
ChatGPT
6 months ago
Javascript Console
7 months ago
Farlight84
7 months ago
chat-gpt
7 months ago
Text to Image AI
7 months ago
talks
8 months ago
Deno.Kv
9 months ago
Darija to Arabic
9 months ago
use blogger ai
9 months ago
any lang to js
9 months ago
Search
9 months ago
Click Here To Chat
10 months ago
Assistant Aoud
10 months ago
New Room
10 months ago
Re Write
10 months ago
economic tutor
10 months ago
Apex
11 months ago
myveryownroom
11 months ago
membantuku
11 months ago
한국인
11 months ago
معلق رياضي
11 months ago
duoda
11 months ago
Tourism guide
11 months ago
frontend styles
11 months ago
Technical Advisor
11 months ago
Vrais ou Faux
a year ago
دليل سفر
a year ago
citation
a year ago
شاعر
a year ago
ChatGPT turbo
No messages
Deno.Kv
+
zip.exe-go's avatar

@zip.exe-go

9 months ago
اعطني مثال عن تخزين قيمة فيها يوزر و كلمة السر بعد مروروها من الهاش ، وخزن مع هاته البيانات : { volume: 0.8, attack: 0.1, decay: 0.2, sustain: 0.5, release: 0.2, }
JPT's avatar

@JPT

9 months ago
zip.exe-go: يمكن تخزين قيمة مع اسم المستخدم وكلمة المرور بشكل مثالي في قاعدة البيانات على النحو التالي:
javascript
const db = await Deno.openKv();

const username = "john123";
const hashedPassword = "hashed_password";
const settings = {
  volume: 0.8,
  attack: 0.1,
  decay: 0.2,
  sustain: 0.5,
  release: 0.2,
};

const userData = {
  username,
  password: hashedPassword,
  settings,
};

await db.put(username, userData);
هذا المثال يفترض أنك قد قمت بتجهيز القيمة المموَّهة لكلمة المرور بالفعل قبل تخزينها في قاعدة البيانات. لاحظ أننا استخدمنا قيمة الاسم (username) كمفتاح لتخزين البيانات. يمكنك تغيير هذا حسب الحاجة إلى نظام المفاتيح الذي تفضله. للوصول إلى هذه البيانات، يمكن استخدام الدالة `get` على النحو التالي:
javascript
const userData = await db.get(username);

if (userData) {
  const settings = userData.settings;
  // استخدم الإعدادات هنا
} else {
  // المستخدم غير موجود في قاعدة البيانات
}
في هذا المثال، ستحصل على قيمة `userData` باستخدام اسم المستخدم كمفتاح، ثم يمكنك الوصول إلى إعدادات (settings) المستخدم واستخدامها كما ترغب.
zip.exe-go's avatar

@zip.exe-go

9 months ago
اعطني مثال عن تخزين قيمة فيها يوزر و كلمة السر مشفرة، وخزن مع هاته البيانات : { volume: 0.8, attack: 0.1, decay: 0.2, sustain: 0.5, release: 0.2, } لستعمل deno.kv
JPT's avatar

@JPT

9 months ago
zip.exe-go: يمكن استخدام Deno.KV لتخزين البيانات التي تحتوي على اسم المستخدم وكلمة المرور المشفرة بالإضافة إلى القيم الأخرى المستخدمة في المثال. يمكن استخدام مفتاح مناسب لتمييز بيانات كل مستخدم. في المثال التالي ، سنستخدم اسم المستخدم كمفتاح:
typescript
import { openKv, KvEntryMaybe } from "deno";

const db = await openKv();

// تخزين بيانات المستخدم
const username = "user1";
const password = "password1";
const encryptedPassword = encrypt(password); // تشفير كلمة المرور

const userData = {
  volume: 0.8,
  attack: 0.1,
  decay: 0.2,
  sustain: 0.5,
  release: 0.2,
};

await db.put(username, {
  password: encryptedPassword,
  ...userData,
});

// استعراض بيانات المستخدم
const userEntry: KvEntryMaybe<any> = await db.get(username);

if (userEntry.value === null) {
  console.log("لم يتم العثور على المستخدم");
} else {
  const decryptedPassword = decrypt(userEntry.value.password); // فك تشفير كلمة المرور
  console.log("اسم المستخدم:", username);
  console.log("كلمة المرور:", decryptedPassword);
  console.log("بيانات المستخدم:", userEntry.value);
}
يرجى ملاحظة أنه يتعين استخدام دوال التشفير وفك التشفير الملائمة لطريقة التشفير المستخدمة في التطبيق. ستحتاج إلى استيراد هذه الدوال واستخدامها في الأمثلة السابقة لضمان تشفير وفك تشفير كلمة المرور بشكل صحيح.
zip.exe-go's avatar

@zip.exe-go

9 months ago
معلومات عن denokv
JPT's avatar

@JPT

9 months ago
zip.exe-go: DenoKV هو قاعدة بيانات رئيسية قابلة للمفتوحة تستخدم لتخزين واسترداد البيانات. يتم تخزين البيانات على شكل أزواج المفتاح والقيمة ، حيث يكون المفتاح من نوع Deno.KvKey والقيمة هي قيمة JavaScript متسلسلة هيكليًا وقابلة للتنفيذ. ترتب المفاتيح ترتيبًا ثلاثيًّا كما هو موضح في وثائق Deno.KvKey. المفاتيح فريدة داخل قاعدة البيانات والقيمة الأخيرة المعينة للمفتاح هي التي يتم إرجاعها عند قراءة المفتاح. يمكن حذف المفاتيح من قاعدة البيانات ، وفي هذه الحالة لن يتم إرجاعها عند قراءة المفاتيح. يمكن أن تكون القيم أي قيمة JavaScript متسلسلة هيكليًا (كائنات ، مصفوفات ، سلاسل ، أرقام ، إلخ). يمكن استخدام القيمة الخاصة Deno.KvU64 لتخزين الأعداد الصحيحة بدون علامة ستينيات 64 في قاعدة البيانات. لا يمكن تداخل هذه القيمة الخاصة ضمن كائنات أو مصفوفات أخرى. بالإضافة إلى العمليات العادية لتحويل قاعدة البيانات ، يدعم القيمة العددية لـ 64 بت بدون علامة أيضًا تحويلات الجمع والحد الأقصى والحد الأدنى. تقوم المفاتيح بترقيم عند الكتابة من خلال تعيين "صورة الإصدار" للمفتاح ، وهو رقم يزداد تزايداً تامًا. تمثل صورة الإصدار إصدارًا من الزوج المفتاح-القيمة في قاعدة البيانات في نقطة زمنية ما ، ويمكن استخدامها لتنفيذ العمليات التعاملية على قاعدة البيانات دون الحاجة إلى أي قفل. يتيح ذلك عمليات ذرية ، ويمكن أن تكون لها ظروف تضمن أن العملية تنجح فقط إذا كانت صورة إصدار الزوج المفتاح-القيمة تطابق صورة إصدار متوقعة. للمفاتيح حد أقصى يبلغ 2048 بايت بعد التسلسل. للقيم حد أقصى يبلغ 64 كيلوبايت بعد التسلسل. التسلسل لكل المفاتيح والقيم نوعًا ما غير شفاف ، ولكن يمكن أن نفترض عادةً أن تسلسل أي قيمة تكون مدى نفس طول سلسلة JSON ناتجة عن تسلسل هذه القيمة نفسها. إذا تجاوزت هذه الحدود ، سيتم رمي استثناء.
Zizwar-gi's avatar

@Zizwar-gi

9 months ago
synopsis and example
JPT's avatar

@JPT

9 months ago
Zizwar-gi: The Deno KV API provides methods for creating and manipulating a key-value database. Here is a synopsis of the methods provided by the API: - atomic(): Create a new Deno.AtomicOperation object for performing atomic transactions. - close(): Close the database connection. - delete(key: KvKey): Delete the value for the given key from the database. - enqueue(value: unknown, options?: { delay?: number; keysIfUndelivered?: Deno.KvKey[]; }): Add a value to the database queue to be delivered to the queue listener. - get(key: KvKey, options?: { consistency?: KvConsistencyLevel; }): Retrieve the value and versionstamp for the given key from the database. - getMany(keys: readonly [...[K in keyof T]: KvKey], options?: { consistency?: KvConsistencyLevel; }): Retrieve multiple values and versionstamps from the database. - listenQueue(options?: { startTime?: number; filters?: Deno.KvKey[][]; }): Listen for values that are added to the database queue. - listenRaw(options?: { startTime?: number; prefixes?: Deno.KvKey[][]; }): Listen for raw changes to the database. - put(key: KvKey, value: unknown, options?: { ifVersion?: KvVersionstamp }): Store the value for the given key in the database. - reset(): Reset the database to its initial empty state. - snapshot(): Create a snapshot of the current database state. Here is an example of how to use the Deno KV API:
javascript
import { openKv } from "https://deno.land/x/kv/mod.ts";

const db = await openKv(); // Open a connection to the key-value database

// Store a value in the database
await db.put(["foo"], "bar");

// Retrieve the value from the database
const result = await db.get(["foo"]);
console.log(result.value); // Output: "bar"

// Delete the value from the database
await db.delete(["foo"]);

// Close the database connection
db.close();
In this example, we first open a connection to the key-value database using the `openKv()` function. Then, we use the `put()` method to store a value with the key `["foo"]` in the database. We can retrieve the value using the `get()` method and print it to the console. Finally, we delete the value from the database using the `delete()` method, and close the database connection using the `close()` method.
Zizwar-gi's avatar

@Zizwar-gi

9 months ago
create code alternative supabase to deno.kv, code is : export cl****Database { #client: supabase.SupabaseClient; constructor(client?: supabase.SupabaseClient) { this.#client = client ?? supabase.createClient( Deno.env.get("SUPABASE_API_URL")!, Deno.env.get("SUPABASE_ANON_KEY")! ); } // async __insertUser(user: DatabaseUser & { accessToken: string }) { const { error } = await this.#client.from("users").upsert( [ { // id: user.userId, avatar_url: user.avatarUrl, access_token: user.accessToken, }, ], { returning: "minimal", where: { username: user.userName }, } ); if (error) { throw new Error(error.message); } } // async getUserByAccessTokenOrThrow( accessToken: string ): Promise { const user = await this.getUserByAccessToken(accessToken); if (user == null) { throw new Error("Could not find user with access token."); } return user; } async getUserByAccessToken( accessToken: string ): Promise { const { data, error } = await this.#client .from("users") .select("id,username,avatar_url") .eq("access_token", accessToken); if (error) { throw new Error(error.message); } if (data.length === 0) { return undefined; } return { userId: data[0].id, userName: data[0].username, avatarUrl: data[0].avatar_url, }; } async getUserByUsername(user: string): Promise { const { data, error } = await this.#client .from("rooms") .select("*") .eq("username", user) .single(); if (error) { throw new Error(error.message); } return data ?? []; } }
JPT's avatar

@JPT

9 months ago
Zizwar-gi: Here's an alternative implementation using Supabase with Deno:
typescript
import { createClient, SupabaseClient } from "@supabase/supabase-js";

interface DatabaseUser {
  userId: string;
  userName: string;
  avatarUrl: string;
}

export class Database {
  #client: SupabaseClient;

  constructor(client?: SupabaseClient) {
    this.#client =
      client ??
      createClient(
        Deno.env.get("SUPABASE_API_URL")!,
        Deno.env.get("SUPABASE_ANON_KEY")!
      );
  }

  async __insertUser(user: DatabaseUser & { accessToken: string }) {
    const { error } = await this.#client
      .from("users")
      .upsert(
        [
          {
            // id: user.userId,
            avatar_url: user.avatarUrl,
            access_token: user.accessToken,
          },
        ],
        {
          returning: "minimal",
          where: { username: user.userName },
        }
      );

    if (error) {
      throw new Error(error.message);
    }
  }

  async getUserByAccessTokenOrThrow(
    accessToken: string
  ): Promise<DatabaseUser> {
    const user = await this.getUserByAccessToken(accessToken);
    if (user == null) {
      throw new Error("Could not find user with access token.");
    }
    return user;
  }

  async getUserByAccessToken(
    accessToken: string
  ): Promise<DatabaseUser | undefined> {
    const { data, error } = await this.#client
      .from("users")
      .select("id,username,avatar_url")
      .eq("access_token", accessToken);

    if (error) {
      throw new Error(error.message);
    }

    if (data.length === 0) {
      return undefined;
    }

    return {
      userId: data[0].id,
      userName: data[0].username,
      avatarUrl: data[0].avatar_url,
    };
  }

  async getUserByUsername(user: string): Promise<any> {
    const { data, error } = await this.#client
      .from("rooms")
      .select("*")
      .eq("username", user)
      .single();

    if (error) {
      throw new Error(error.message);
    }

    return data ?? [];
  }
}
This code creates a `Database` class that uses Supabase's JavaScript client to interact with a Supabase database. It includes methods for inserting and retrieving user data from the "users" table. The constructor takes an optional Supabase client, allowing you to pass in a pre-configured client or create a new one using environment variables.
Zizwar-gi's avatar

@Zizwar-gi

9 months ago
تريد ان تغير لي من قاعدة بيانات supabase الى deno.kv() اريد طريقة التخزين والجلب ان تعتمد على deno.kv وليس supabase , اعد صياغة كودي وفق ماطلبته منك : export cl****Database { #client: supabase.SupabaseClient; constructor(client?: supabase.SupabaseClient) { this.#client = client ?? supabase.createClient( Deno.env.get("SUPABASE_API_URL")!, Deno.env.get("SUPABASE_ANON_KEY")! ); } // async __insertUser(user: DatabaseUser & { accessToken: string }) { const { error } = await this.#client.from("users").upsert( [ { // id: user.userId, avatar_url: user.avatarUrl, access_token: user.accessToken, }, ], { returning: "minimal", where: { username: user.userName }, } ); if (error) { throw new Error(error.message); } } // async getUserByAccessTokenOrThrow( accessToken: string ): Promise { const user = await this.getUserByAccessToken(accessToken); if (user == null) { throw new Error("Could not find user with access token."); } return user; } async getUserByAccessToken( accessToken: string ): Promise { const { data, error } = await this.#client .from("users") .select("id,username,avatar_url") .eq("access_token", accessToken); if (error) { throw new Error(error.message); } if (data.length === 0) { return undefined; } return { userId: data[0].id, userName: data[0].username, avatarUrl: data[0].avatar_url, }; } async getUserByUsername(user: string): Promise { const { data, error } = await this.#client .from("rooms") .select("*") .eq("username", user) .single(); if (error) { throw new Error(error.message); } return data ?? []; } {
JPT's avatar

@JPT

9 months ago
Zizwar-gi: export class Database { #db: Deno.KvStorage; constructor(db: Deno.KvStorage) { this.#db = db; } async __insertUser(user: DatabaseUser & { accessToken: string }) { const key = ["users", user.userName]; const value = { id: user.userId, avatar_url: user.avatarUrl, access_token: user.accessToken, }; await this.#db.put(key, JSON.stringify(value)); } async getUserByAccessTokenOrThrow(accessToken: string): Promise { const user = await this.getUserByAccessToken(accessToken); if (user == null) { throw new Error("Could not find user with access token."); } return user; } async getUserByAccessToken(accessToken: string): Promise { const entries = await this.#db.list({ prefix: "users", }); for (const entry of entries) { const key = entry.key; const value = JSON.parse(entry.value); if (value.access_token === accessToken) { return { userId: value.id, userName: key[1], avatarUrl: value.avatar_url, }; } } return undefined; } async getUserByUsername(userName: string): Promise { const entries = await this.#db.list({ prefix: "rooms", }); for (const entry of entries) { const key = entry.key; const value = JSON.parse(entry.value); if (value.username === userName) { return value; } } return []; } } // Usage example: const db = new Database(Deno.openKv()); await db.__insertUser({ userId: "123", userName: "john", avatarUrl: "https://example.com/avatar.jpg", accessToken: "abc123" }); const user = await db.getUserByAccessTokenOrThrow("abc123"); console.log(user);
Zizwar-gi's avatar

@Zizwar-gi

9 months ago
replace supabase to deno.kv in this code : async insertUser(user: DatabaseUser & { accessToken: string }) { const { data, error } = await this.#client .from("users") .select("*") .eq("username", user.userName); if (error) { throw new Error(error.message); } if (data.length > 0) { // Username already exists, update the existing record const { error: updateError } = await this.#client .from("users") .update({ avatar_url: user.avatarUrl, access_token: user.accessToken, }) .eq("username", user.userName); if (updateError) { throw new Error(updateError.message); } } else { // Username does not exist, insert a new record const { error: insertError } = await this.#client.from("users").upsert( [ { username: user.userName, avatar_url: user.avatarUrl, access_token: user.accessToken, }, ], { returning: "minimal" } ); if (insertError) { throw new Error(insertError.message); } } }
JPT's avatar

@JPT

9 months ago
Zizwar-gi: async insertUser(user: DatabaseUser & { accessToken: string }) { const db = await Deno.openKv(); const result = await db.get(["users", user.userName]); const existingUser = result.value; if (existingUser) { // Username already exists, update the existing record await db.put(["users", user.userName], { avatar_url: user.avatarUrl, access_token: user.accessToken, }); } else { // Username does not exist, insert a new record await db.put(["users", user.userName], { username: user.userName, avatar_url: user.avatarUrl, access_token: user.accessToken, }); } }
Zizwar-gi's avatar

@Zizwar-gi

9 months ago
r SELECT * FROM messages WHERE to_tsvector('english', message) @@ to_tsquery('english', $1) ORDER BY ts_rank(to_tsvector('english', message), to_tsquery('english', $1)) DESC; `, [searchTerm]);eplace sql to deno.kv(): sql ``
JPT's avatar

@JPT

9 months ago
Zizwar-gi: const db = await Deno.openKv(); const messages = []; const iterator = db.iter({ prefix: "messages:" }); for await (const { key, value } of iterator) { messages.push({ key, value }); } const results = []; for (const message of messages) { if (message.value) { const { message: msg } = JSON.parse(message.value.toString()); const rank = rankMessage(msg, searchTerm); results.push({ message: msg, rank }); } } results.sort((a, b) => b.rank - a.rank); const finalResults = results.map((result) => result.message); console.log(finalResults); db.close(); function rankMessage(message, searchTerm) { const messageVector = Deno.std.uuid.generate().toString(); const queryVector = Deno.std.uuid.generate().toString(); const messageRank = Math.random(); // Replace with actual ranking logic using ts_rank() return messageRank; }
Deno.Kv
Created by zip.exe-go,9 months ago
Answer from what is in this file:--A key-value database that can be used to store and retrieve data. Data is stored as key-value pairs, where the key is a Deno.KvKey and the value is an arbitrary structured-serializable JavaScript value. Keys are ordered lexicographically as described in the documentation for Deno.KvKey. Keys are unique within a database, and the last value set for a given key is the one that is returned when reading the key. Keys can be deleted from the database, in which case they will no longer be returned when reading keys. Values can be any structured-serializable JavaScript value (objects, arrays, strings, numbers, etc.). The special value Deno.KvU64 can be used to store 64-bit unsigned integers in the database. This special value can not be nested within other objects or arrays. In addition to the regular database mutation operations, the unsigned 64-bit integer value also supports sum, max, and min mutations. Keys are versioned on write by assigning the key an ever-increasing "versionstamp". The versionstamp represents the version of a key-value pair in the database at some point in time, and can be used to perform transactional operations on the database without requiring any locking. This is enabled by atomic operations, which can have conditions that ensure that the operation only succeeds if the versionstamp of the key-value pair matches an expected versionstamp. Keys have a maximum length of 2048 bytes after serialization. Values have a maximum length of 64 KiB after serialization. Serialization of both keys and values is somewhat opaque, but one can usually assume that the serialization of any value is about the same length as the resulting string of a JSON serialization of that same value. If theses limits are exceeded, an exception will be thrown. Methods atomic(): AtomicOperation Create a new Deno.AtomicOperation object which can be used to perform an atomic transaction on the database. This does not perform any operations on the database - the atomic transaction must be committed explicitly using the Deno.AtomicOperation.commit method once all checks and mutations have been added to the operation. close(): void Close the database connection. This will prevent any further operations from being performed on the database, and interrupt any in-flight operations immediately. delete(key: KvKey): Promise<void> Delete the value for the given key from the database. If no value exists for the key, this operation is a no-op. const db = await Deno.openKv(); await db.delete(["foo"]); enqueue(value: unknown, options?: { delay?: number; keysIfUndelivered?: Deno.KvKey[]; }): Promise<KvCommitResult> Add a value into the database queue to be delivered to the queue listener via Deno.Kv.listenQueue. const db = await Deno.openKv(); await db.enqueue("bar"); The delay option can be used to specify the delay (in milliseconds) of the value delivery. The default delay is 0, which means immediate delivery. const db = await Deno.openKv(); await db.enqueue("bar", { delay: 60000 }); The keysIfUndelivered option can be used to specify the keys to be set if the value is not successfully delivered to the queue listener after several attempts. The values are set to the value of the queued message. const db = await Deno.openKv(); await db.enqueue("bar", { keysIfUndelivered: [["foo", "bar"]] }); get<T = unknown>(key: KvKey, options?: { consistency?: KvConsistencyLevel; }): Promise<KvEntryMaybe<T>> Retrieve the value and versionstamp for the given key from the database in the form of a Deno.KvEntryMaybe. If no value exists for the key, the returned entry will have a null value and versionstamp. const db = await Deno.openKv(); const result = await db.get(["foo"]); result.key; // ["foo"] result.value; // "bar" result.versionstamp; // "00000000000000010000" The consistency option can be used to specify the consistency level for the read operation. The default consistency level is "strong". Some use cases can benefit from using a weaker consistency level. For more information on consistency levels, see the documentation for Deno.KvConsistencyLevel. getMany<T extends readonly unknown[]>(keys: readonly [...[K in keyof T]: KvKey], options?: { consistency?: KvConsistencyLevel; }): Promise<[K in keyof T]: KvEntryMaybe<T[K]>> Retrieve multiple values and versionstamps from the database in the form of an array of Deno.KvEntryMaybe objects. The returned array will have the same length as the keys array, and the entries will be in the same order as the keys. If no value exists for a given key, the returned entry will have a null value and versionstamp. const db = await Deno.openKv(); const result = await db.getMany([["foo"], ["baz"]]); result[0].key; // ["foo"] result[0].value; // "bar" result[0].versionstamp; // "00000000000000010000" result[1].key; // ["baz"] result[1].value; // null result[1].versionstamp; // null The consistency option can be used to specify the consistency level for the read operation.
Change Color