@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 +1 -1
- package/src/model/core/runtime.ts +5 -1
- package/tests/snippets/x-1.ts +22 -0
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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);
|