Web Developer
Hello,
I'm trying to use the tablesDB class with .createRow. I've generated types; but when I apply the type, it still comes back as Promise. Ideas?
Votes
0
Replies
4
Participants
2
Messages
5
Web Developer
Hello,
I'm trying to use the tablesDB class with .createRow. I've generated types; but when I apply the type, it still comes back as Promise. Ideas?
works fine for me, can you share your generated types file? does it only happen with auto generated types?
Rank 1: Thread
Good morning! Here's my typefile ```ts
import type { Models } from 'appwrite';
// This file is auto-generated by the Appwrite CLI.
// You can regenerate it by running appwrite types --language ts ./types.
export enum SubjectType {
USER = "user",
MESSAGE = "message"
}
export enum Status {
PENDING = "pending",
REVIEWING = "reviewing",
RESOLVED = "resolved"
}
export enum Outcome {
NONE = "none",
WARNING = "warning",
SUSPENDED = "suspended",
BANNED = "banned"
}
export type Rooms = Models.Row & {
isSystem: boolean;
name: string;
messages: Messages[];
}
export type Messages = Models.Row & {
battery: number;
previousContent: string[] | null;
content: string;
deleted: boolean;
room: Rooms;
user: Users;
}
export type Users = Models.Row & {
flags: number;
nickname: string;
suspendedUntil: string | null;
messages: Messages[];
reports: Reports[];
reviewedReports: Reports[];
}
export type Reports = Models.Row & {
subjectType: SubjectType;
reason: string;
details: string | null;
status: Status;
outcome: Outcome | null;
moderatorReason: string | null;
moderatorNotes: string | null;
room: Rooms;
subjectUser: Users;
subjectMessage: Messages;
reportedBy: Users;
claimedBy: Users;
reviewedBy: Users;
contextIds: string[] | null;
}
export type Notifications = Models.Row & {
archived: boolean;
title: string;
message: string;
user: Users;
reads: NotificationRead[];
}
export type NotificationRead = Models.Row & {
notification: Notifications;
user: Users;
}
Here is how I setup my classes, too ```ts
const appwriteClient = new Client()
.setEndpoint(env.APPWRITE_ENDPOINT)
.setProject(env.APPWRITE_PROJECT_ID)
.setKey(env.APPWRITE_API_KEY);
const tablesDB = new TablesDB(appwriteClient);
const db = new Database(tablesDB);```
and in the class ```ts
import type { TablesDB } from 'node-appwrite';
import type { Messages as MessageSchema } from '../../types/appwrite.js';
export default class Messages {
db: TablesDB;
constructor(db: TablesDB) {
this.db = db;
}
/**
* Sends a message to a specific chat room.
* @param room The ID of the room to which the message will be sent.
* @param message The message to send.
*/
async sendMessageToRoom(room: string, message: MessageSchema) {
return await this.db.createRow<MessageSchema>({
databaseId: '6910fa690012f5ea1035', // from appwrite.config.json - tlb_dev
tableId: 'messages',
rowId: message.$id, // use Appwrite's $id field
data: {
content: message.content,
user: message.user.$id, // relationship field - pass the user ID
room: room, // relationship field - pass the room ID
battery: message.battery,
deleted: false, // default value
previousContent: [], // default empty array for edit history
},
});
}
}
Rank 1: Thread
not for sure, honestly. Before I used appwrite I used prisma which does the same generated types thing...
Rank 1: Thread
tried restarting my ts server too