classes to access db

Is this code possible? Copilot says it's valid but I cannot find it in the documentation
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
4 Replies
Seren_Modz 21
Seren_Modz 219mo ago
unfortunately, that is not how drizzle works. i would highly recommend reading through the docs, which can be found here: https://orm.drizzle.team/docs/overview
Drizzle ORM - Overview
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
rodrigo
rodrigoOP9mo ago
BTW, are you aware of any examples in js/ts using OOP with drizzle-orm to create standard CRUD operations? thx!
Seren_Modz 21
Seren_Modz 219mo ago
as of right now, there only consists of the standard SQL-like syntax syntax and the Queries API. however, currently the queries API only supports findFirst and findMany operations and all other CRUD operations (create, update, delete) require the SQL-like syntax. create/insert: https://orm.drizzle.team/docs/insert update: https://orm.drizzle.team/docs/update delete: https://orm.drizzle.team/docs/delete in my opinion, the docs are the best place to learn majority, if not the whole of drizzle. from using the docs, i myself have managed to learn quite a lot of how to use it.
Drizzle ORM - Insert
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle ORM - Update
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle ORM - Delete
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Seren_Modz 21
Seren_Modz 219mo ago
my apologies for the constant acknowledgement of the docs, i just think its the best place to learn the ins and outs of the library.
Want results from more Discord servers?
Add your server