@apisr/drizzle-model 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apisr/drizzle-model",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "lint": "eslint . --max-warnings 0",
@@ -238,7 +238,11 @@ export function makeModelRuntime(config: {
238
238
  const runner = async (mState: MutateState) => {
239
239
  const table = (config.schema as any)[config.tableName];
240
240
  const q = (config.db as any).insert(table).values(mState.value);
241
- return await execReturn(q, mState, config.dialect);
241
+ const result = await execReturn(q, mState, config.dialect);
242
+ if (!Array.isArray(mState.value) && Array.isArray(result)) {
243
+ return result[0];
244
+ }
245
+ return result;
242
246
  };
243
247
 
244
248
  return new MutateResult(
@@ -0,0 +1,22 @@
1
+ import { esc, modelBuilder } from "src/model";
2
+ import { db } from "../db";
3
+ import { relations } from "../relations";
4
+ import * as schema from "../schema";
5
+
6
+ const model = modelBuilder({
7
+ schema,
8
+ db,
9
+ relations,
10
+ dialect: "PostgreSQL",
11
+ });
12
+
13
+ // create model
14
+ const userModel = model("user", {});
15
+
16
+ const user = await userModel
17
+ .where({
18
+ age: esc(12),
19
+ })
20
+ .findFirst();
21
+
22
+ console.log(user);