-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
203 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { entsTableFactory } from "convex-ents"; | ||
import { | ||
customAction, | ||
customCtx, | ||
customMutation, | ||
customQuery, | ||
} from "convex-helpers/server/customFunctions"; | ||
import { GenericDatabaseReader, GenericDatabaseWriter } from "convex/server"; | ||
import { DataModel } from "./_generated/dataModel"; | ||
import { | ||
internalMutation as baseInternalMutation, | ||
internalQuery as baseInternalQuery, | ||
mutation as baseMutation, | ||
query as baseQuery, | ||
} from "./_generated/server"; | ||
import { entDefinitions } from "./schema"; | ||
|
||
type LegacyTables = "messages" | "users"; | ||
|
||
export const query = customQuery( | ||
baseQuery, | ||
customCtx(async (ctx) => { | ||
return { | ||
table: entsTableFactory(ctx, entDefinitions), | ||
db: ctx.db as unknown as GenericDatabaseReader< | ||
Pick<DataModel, LegacyTables> | ||
>, | ||
}; | ||
}), | ||
); | ||
|
||
export const internalQuery = customQuery( | ||
baseInternalQuery, | ||
customCtx(async (ctx) => { | ||
return { | ||
table: entsTableFactory(ctx, entDefinitions), | ||
db: ctx.db as unknown as GenericDatabaseReader< | ||
Pick<DataModel, LegacyTables> | ||
>, | ||
}; | ||
}), | ||
); | ||
|
||
export const mutation = customMutation( | ||
baseMutation, | ||
customCtx(async (ctx) => { | ||
return { | ||
table: entsTableFactory(ctx, entDefinitions), | ||
db: ctx.db as GenericDatabaseWriter<Pick<DataModel, LegacyTables>>, | ||
}; | ||
}), | ||
); | ||
|
||
export const internalMutation = customMutation( | ||
baseInternalMutation, | ||
customCtx(async (ctx) => { | ||
return { | ||
table: entsTableFactory(ctx, entDefinitions), | ||
db: ctx.db as GenericDatabaseWriter<Pick<DataModel, LegacyTables>>, | ||
}; | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { v } from "convex/values"; | ||
import { mutation, query } from "./functions"; | ||
|
||
export const getMessageByGroupId = query({ | ||
args:{id:v.id('groups')}, | ||
handler:async (ctx, args)=>{ | ||
return await ctx.table('messages').filter((q)=>q.eq(q.field('groupId'), args.id)); | ||
} | ||
}) | ||
|
||
|
||
export const createMessage = mutation({ | ||
args:{content:v.string(), to:v.id('users'), from:v.id('users')}, | ||
handler:async (ctx, args) => { | ||
|
||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { defineEnt, defineEntSchema, getEntDefinitions } from "convex-ents"; | ||
import { v } from "convex/values"; | ||
|
||
const schema = defineEntSchema({ | ||
users:defineEnt({ | ||
name:v.string(), | ||
description: v.string(), | ||
email:v.string(), | ||
publicKey:v.string(), | ||
}).edge('session').edges('group', {to:'groups', table:"groupchat"}), | ||
|
||
messages:defineEnt({ | ||
content:v.string() | ||
}).edge('group'), | ||
|
||
sessions:defineEnt({ | ||
deviceId:v.string(), | ||
}).edge('user'), | ||
|
||
groups: defineEnt({ | ||
name:v.string(), | ||
description:v.string(), | ||
isDm:v.boolean(), | ||
owner:v.optional(v.id('users')) | ||
}).edge('message').edges('user', {to:'users', table:"groupchat"}) | ||
}) | ||
|
||
export default schema; | ||
|
||
export const entDefinitions = getEntDefinitions(schema); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GenericEnt, GenericEntWriter } from "convex-ents"; | ||
import { CustomCtx } from "convex-helpers/server/customFunctions"; | ||
import { TableNames } from "./_generated/dataModel"; | ||
import { mutation, query } from "./functions"; | ||
import { entDefinitions } from "./schema"; | ||
|
||
export type QueryCtx = CustomCtx<typeof query>; | ||
export type MutationCtx = CustomCtx<typeof mutation>; | ||
|
||
export type Ent<TableName extends TableNames> = GenericEnt< | ||
typeof entDefinitions, | ||
TableName | ||
>; | ||
export type EntWriter<TableName extends TableNames> = GenericEntWriter< | ||
typeof entDefinitions, | ||
TableName | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters