Home / File/ sqlite.schema.ts — drizzle-orm Source File

sqlite.schema.ts — drizzle-orm Source File

Architecture documentation for sqlite.schema.ts, a typescript file in the drizzle-orm codebase. 2 imports, 2 dependents.

File typescript DrizzleORM RelationalQuery 2 imports 2 dependents 7 functions

Entity Profile

Dependency Diagram

graph LR
  8e6540c2_b1bc_2b59_6309_c7551073ed36["sqlite.schema.ts"]
  25248a9d_ba06_2b33_4421_8575da2f9c34["sqlite-core"]
  8e6540c2_b1bc_2b59_6309_c7551073ed36 --> 25248a9d_ba06_2b33_4421_8575da2f9c34
  690f7dfc_0aea_9ee8_d6e7_26bbb3689031["drizzle-orm"]
  8e6540c2_b1bc_2b59_6309_c7551073ed36 --> 690f7dfc_0aea_9ee8_d6e7_26bbb3689031
  e4440eea_b86b_a235_5acf_9842927449bc["bettersqlite.test.ts"]
  e4440eea_b86b_a235_5acf_9842927449bc --> 8e6540c2_b1bc_2b59_6309_c7551073ed36
  b433112d_d5fe_109f_6111_a1fde0e203e7["turso.test.ts"]
  b433112d_d5fe_109f_6111_a1fde0e203e7 --> 8e6540c2_b1bc_2b59_6309_c7551073ed36
  style 8e6540c2_b1bc_2b59_6309_c7551073ed36 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { type AnySQLiteColumn, integer, primaryKey, sqliteTable, text } from 'drizzle-orm/sqlite-core';

import { relations, sql } from 'drizzle-orm';

export const usersTable = sqliteTable('users', {
	id: integer('id').primaryKey({ autoIncrement: true }),
	name: text('name').notNull(),
	verified: integer('verified').notNull().default(0),
	invitedBy: integer('invited_by').references((): AnySQLiteColumn => usersTable.id),
});
export const usersConfig = relations(usersTable, ({ one, many }) => ({
	invitee: one(usersTable, {
		fields: [usersTable.invitedBy],
		references: [usersTable.id],
	}),
	usersToGroups: many(usersToGroupsTable),
	posts: many(postsTable),
}));

export const groupsTable = sqliteTable('groups', {
	id: integer('id').primaryKey({ autoIncrement: true }),
	name: text('name').notNull(),
	description: text('description'),
});
export const groupsConfig = relations(groupsTable, ({ many }) => ({
	usersToGroups: many(usersToGroupsTable),
}));

export const usersToGroupsTable = sqliteTable(
	'users_to_groups',
	{
		id: integer('id').primaryKey({ autoIncrement: true }),
		userId: integer('user_id', { mode: 'number' }).notNull().references(
			() => usersTable.id,
		),
		groupId: integer('group_id', { mode: 'number' }).notNull().references(
			() => groupsTable.id,
		),
	},
	(t) => ({
		pk: primaryKey(t.userId, t.groupId),
	}),
);
export const usersToGroupsConfig = relations(usersToGroupsTable, ({ one }) => ({
	group: one(groupsTable, {
		fields: [usersToGroupsTable.groupId],
		references: [groupsTable.id],
	}),
	user: one(usersTable, {
		fields: [usersToGroupsTable.userId],
		references: [usersTable.id],
	}),
}));

export const postsTable = sqliteTable('posts', {
	id: integer('id').primaryKey({ autoIncrement: true }),
	content: text('content').notNull(),
	ownerId: integer('owner_id', { mode: 'number' }).references(
		() => usersTable.id,
	),
	createdAt: integer('created_at', { mode: 'timestamp_ms' })
		.notNull().default(sql`current_timestamp`),
});
export const postsConfig = relations(postsTable, ({ one, many }) => ({
	author: one(usersTable, {
		fields: [postsTable.ownerId],
		references: [usersTable.id],
	}),
	comments: many(commentsTable),
}));

export const commentsTable = sqliteTable('comments', {
	id: integer('id').primaryKey({ autoIncrement: true }),
	content: text('content').notNull(),
	creator: integer('creator', { mode: 'number' }).references(
		() => usersTable.id,
	),
	postId: integer('post_id', { mode: 'number' }).references(() => postsTable.id),
	createdAt: integer('created_at', { mode: 'timestamp_ms' })
		.notNull().default(sql`current_timestamp`),
});
export const commentsConfig = relations(commentsTable, ({ one, many }) => ({
	post: one(postsTable, {
		fields: [commentsTable.postId],
		references: [postsTable.id],
	}),
	author: one(usersTable, {
		fields: [commentsTable.creator],
		references: [usersTable.id],
	}),
	likes: many(commentLikesTable),
}));

export const commentLikesTable = sqliteTable('comment_likes', {
	id: integer('id').primaryKey({ autoIncrement: true }),
	creator: integer('creator', { mode: 'number' }).references(
		() => usersTable.id,
	),
	commentId: integer('comment_id', { mode: 'number' }).references(
		() => commentsTable.id,
	),
	createdAt: integer('created_at', { mode: 'timestamp_ms' })
		.notNull().default(sql`current_timestamp`),
});
export const commentLikesConfig = relations(commentLikesTable, ({ one }) => ({
	comment: one(commentsTable, {
		fields: [commentLikesTable.commentId],
		references: [commentsTable.id],
	}),
	author: one(usersTable, {
		fields: [commentLikesTable.creator],
		references: [usersTable.id],
	}),
}));

Domain

Subdomains

Dependencies

  • drizzle-orm
  • sqlite-core

Frequently Asked Questions

What does sqlite.schema.ts do?
sqlite.schema.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, RelationalQuery subdomain.
What functions are defined in sqlite.schema.ts?
sqlite.schema.ts defines 7 function(s): commentLikesConfig, commentsConfig, groupsConfig, postsConfig, usersConfig, usersToGroupsConfig, usersToGroupsTable.
What does sqlite.schema.ts depend on?
sqlite.schema.ts imports 2 module(s): drizzle-orm, sqlite-core.
What files import sqlite.schema.ts?
sqlite.schema.ts is imported by 2 file(s): bettersqlite.test.ts, turso.test.ts.
Where is sqlite.schema.ts in the architecture?
sqlite.schema.ts is located at integration-tests/tests/relational/sqlite.schema.ts (domain: DrizzleORM, subdomain: RelationalQuery, directory: integration-tests/tests/relational).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free